Use Array#unshift in the LL XML grammar.
Using Array#+ for large sets (e.g. in the benchmarks) is _really_ slow. Interesting enough Array#unshift uses as much memory as the Racc parser and is about as fast, even though it has to move memory around.
This commit is contained in:
parent
f94407ee9d
commit
dd626c10d3
|
@ -35,18 +35,22 @@ document
|
||||||
;
|
;
|
||||||
|
|
||||||
expressions
|
expressions
|
||||||
= expression expressions { val[0] + val[1] }
|
= expression expressions
|
||||||
|
{
|
||||||
|
val[1].unshift(val[0])
|
||||||
|
val[1]
|
||||||
|
}
|
||||||
| _
|
| _
|
||||||
;
|
;
|
||||||
|
|
||||||
expression
|
expression
|
||||||
= doctype
|
= doctype { val[0] }
|
||||||
| cdata
|
| cdata { val[0] }
|
||||||
| comment
|
| comment { val[0] }
|
||||||
| proc_ins
|
| proc_ins { val[0] }
|
||||||
| text
|
| text { val[0] }
|
||||||
| element
|
| element { val[0] }
|
||||||
| xml_decl
|
| xml_decl { val[0] }
|
||||||
;
|
;
|
||||||
|
|
||||||
# Doctypes
|
# Doctypes
|
||||||
|
@ -156,7 +160,11 @@ attributes
|
||||||
;
|
;
|
||||||
|
|
||||||
attributes_
|
attributes_
|
||||||
= attribute attributes { [val[0]] + val[1] }
|
= attribute attributes
|
||||||
|
{
|
||||||
|
val[1].unshift(val[0])
|
||||||
|
val[1]
|
||||||
|
}
|
||||||
| _
|
| _
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -182,10 +190,7 @@ attribute_name
|
||||||
# XML declarations
|
# XML declarations
|
||||||
|
|
||||||
xml_decl
|
xml_decl
|
||||||
= T_XML_DECL_START attributes T_XML_DECL_END
|
= T_XML_DECL_START attributes T_XML_DECL_END { on_xml_decl(val[1]) }
|
||||||
{
|
|
||||||
on_xml_decl(val[1])
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
# Plain text
|
# Plain text
|
||||||
|
|
Loading…
Reference in New Issue