How would I optimize this parser?
T.D.Spenser
thoughdipenser.net at gmail.com
Sat Oct 30 19:53:59 PDT 2010
I wrote a simple parser in D. The language for it looks like this:
[tagName content content [childTagName] [childTagName more content]]
The parser is here:
http://thoughtdispenser.net/files/parser.d
Unfortunately, it's quite slow. Can anyone point out what might be the issue(s)?
begin 644 parser.d
M<'5B;&EC(&-L87-S(%-T871I8U!A<G-E<B!["B`@("!P=6)L:6,@<W1A=&EC
M(%1A9TYO9&4@<&%R<V4H<W1R:6YG(&-O9&4I>PH@("`@("`@(%1A9TYO9&4@
M<F]O="`](&YE=R!486=.;V1E*"(B*3L*("`@("`@("!I9B`H8V]D92YL96YG
M=&@@/B`P*2!["B`@("`@("`@("`@(&EN="!C;VYT96YT16YD(#T@<&%R<V5"
M;V1Y*&-O9&4L(')O;W0L(#`I.PH@("`@("`@("`@("!I9B`H8V]N=&5N=$5N
M9"`\(&-O9&4N;&5N9W1H*2!["B`@("`@("`@("`@("`@("!T:')O=R!N97<@
M17AC97!T:6]N*")4:&5R92!A<F4 at 97AT<F$@8VQO<VEN9R!B<F%C:V5T<R(I
M.PH@("`@("`@("`@("!]"B`@("`@("`@?0H@("`@("`@(')E='5R;B!R;V]T
M.PH@("`@?0H*("`@('-T871I8R!P=6)L:6,@:6YT('!A<G-E0F]D>2AS=')I
M;F<@=&5X="P at 5&%G3F]D92!C=7)R96YT3F]D92P@:6YT('!O<VET:6]N*7L*
M("`@("`@("!W:&EL92`H<&]S:71I;VX@/"!T97AT+FQE;F=T:"D@>PH@("`@
M("`@("`@("!I9B`H=&5X=%MP;W-I=&EO;ET@/3T@)ULG*2!["B`@("`@("`@
M("`@("`@("!P;W-I=&EO;B`]('!A<G-E3F]D92AT97AT+"!C=7)R96YT3F]D
M92P@<&]S:71I;VX@*R`Q*3L*("`@("`@("`@("`@("`@('!O<VET:6]N*RL[
M"B`@("`@("`@("`@('T at 96QS92!I9B`H=&5X=%MP;W-I=&EO;ET@/3T@)UTG
M*2!["B`@("`@("`@("`@("`@("!R971U<FX@<&]S:71I;VX["B`@("`@("`@
M("`@('T at 96QS92!["B`@("`@("`@("`@("`@("!P;W-I=&EO;B`]('!A<G-E
M5&5X="AT97AT+"!C=7)R96YT3F]D92P@<&]S:71I;VXI.PH@("`@("`@("`@
M("!]"B`@("`@("`@?0H@("`@("`@(')E='5R;B!T97AT+FQE;F=T:#L*("`@
M('T*"B`@("!S=&%T:6,@<'5B;&EC(&EN="!P87)S951E>'0H<W1R:6YG('1E
M>'0L(%1A9TYO9&4 at 8W5R<F5N=$YO9&4L(&EN="!S=&%R="E["B`@("`@("`@
M+R]A<W-E<G0H=&5X=%MS=&%R=%T@(3T@)ULG("8F('1E>'1;<W1A<G1=("$]
M("==)RD["B`@("`@("`@:6YT('!O<VET:6]N(#T@<W1A<G0["B`@("`@("`@
M=VAI;&4@*'!O<VET:6]N(#P@=&5X="YL96YG=&@I('L*("`@("`@("`@("`@
M:68@*'1E>'1;<&]S:71I;VY=(#T]("=;)R!\?"!T97AT6W!O<VET:6]N72`]
M/2`G72<I('L*("`@("`@("`@("`@("`@(&)R96%K.PH@("`@("`@("`@("!]
M"B`@("`@("`@("`@('!O<VET:6]N*RL["B`@("`@("`@?0H@("`@("`@('-T
M<FEN9R!T97AT0VAA<G,@/2!T97AT6W-T87)T("XN('!O<VET:6]N73L*("`@
M("`@("!497AT3F]D92!T97AT3F]D92`](&YE=R!497AT3F]D92AT97AT0VAA
M<G,I.PH@("`@("`@(&-U<G)E;G1.;V1E+F%D9$-H:6QD*'1E>'1.;V1E*3L*
M("`@("`@("!R971U<FX@<&]S:71I;VX["B`@("!]"@H@("`@<W1A=&EC('!U
M8FQI8R!I;G0 at 9V5T3F%M945N9"AS=')I;F<@=&5X="P@:6YT('!O<VET:6]N
M*7L*("`@("`@("!W:&EL92`H<&]S:71I;VX@/"!T97AT+FQE;F=T:"D@>PH@
M("`@("`@("`@("!S=VET8V@@*'1E>'1;<&]S:71I;VY=*2!["B`@("`@("`@
M("`@("`@("!C87-E("<@)RP@)UQT)RP@)UQN)RP@)UQR)RP@)UTG+"`G6R<Z
M"B`@("`@("`@("`@("`@("`@("`@<F5T=7)N('!O<VET:6]N.PH@("`@("`@
M("`@("`@("`@8G)E86L["B`@("`@("`@("`@("`@("!D969A=6QT.B`*("`@
M("`@("`@("`@("`@("`@("`O+V1O(&YO=&AI;F<L(&YE960@=&AI<R!T;R!A
M=F]I9"!S:6QL>2!E<G)O<G,*("`@("`@("`@("`@?0H@("`@("`@("`@("!P
M;W-I=&EO;BLK.PH@("`@("`@('T*("`@("`@("`O+V%S<V5R="AF86QS92D[
M"B`@("`@("`@=&AR;W<@;F5W($5X8V5P=&EO;B at B4V]M92!T86=S(&%R92!N
M;W0 at 8VQO<V5D(BD["B`@("!]"@H@("`@<W1A=&EC('!U8FQI8R!I;G0@<&%R
M<V5.;V1E*'-T<FEN9R!T97AT+"!486=.;V1E('!A<F5N=$YO9&4L(&EN="!S
M=&%R="E["B`@("`@("`@:6YT('!O<VET:6]N(#T at 9V5T3F%M945N9"AT97AT
M+"!S=&%R="D["B`@("`@("`@<W1R:6YG(&YA;64@/2!T97AT6W-T87)T("XN
M('!O<VET:6]N73L*("`@("`@("!486=.;V1E('1H:7-.;V1E(#T@;F5W(%1A
M9TYO9&4H;F%M92D["@H@("`@("`@(&EF("AT97AT6W!O<VET:6]N72`A/2`G
M6R<@)B8@=&5X=%MP;W-I=&EO;ET@(3T@)UTG*2!["B`@("`@("`@("`@('!O
M<VET:6]N*RL[("\O<VMI<"!T:&4@=VAI=&5S<&%C92!C:&%R('1H870@<V5P
M87)A=&5S(&YA;64 at 86YD(&)O9'D*("`@("`@("!]"@H@("`@("`@(&EN="!T
M86=%;F0@/2!P87)S94)O9'DH=&5X="P@=&AI<TYO9&4L('!O<VET:6]N*3L*
M("`@("`@("!I9B`H=&%G16YD(#X]('1E>'0N;&5N9W1H*2!["B`@("`@("`@
M("`@('1H<F]W(&YE=R!%>&-E<'1I;VXH(E-O;64@=&%G(&ES;B=T(&-L;W-E
M9"(I.PH@("`@("`@('T*("`@("`@("!P87)E;G1.;V1E+F%D9$-H:6QD*'1H
M:7-.;V1E*3L*("`@("`@("!R971U<FX@=&%G16YD.PH@("`@?0I]"@IP=6)L
M:6, at 86)S=')A8W0 at 8VQA<W, at 3F]D92!["B`@("!.;V1E('!A<F5N=#L*("`@
M(`H@("`@<'5B;&EC(&%B<W1R86-T('-T<FEN9R!T;U-T<FEN9R at I.PH@("`@
M"B`@("!P=6)L:6, at 3F]D92!G971087)E;G0H*7L*("`@("`@("!R971U<FX@
M<&%R96YT.PH@("`@?0I]"@IP=6)L:6, at 8VQA<W, at 5&%G3F]D92`Z($YO9&4@
M>PH@("`@<W1R:6YG(&YA;64["B`@("!.;V1E6UT at 8VAI;&1R96X["@H@("`@
M<'5B;&EC('1H:7,H<W1R:6YG(&YA;64L($YO9&5;72!C:&EL9')E;BXN+BE[
M("\O8V%N)W0@:&%V92!T=V\@8V]N<W1R=6-T;W)S(&QI:V4@:6X at 2F%V80H@
M("`@("`@('1H:7,N;F%M92`](&YA;64["B`@("`@("`@:68@*&-H:6QD<F5N
M+FQE;F=T:"`^(#`I('L*("`@("`@("`@("`@=&AI<RYC:&EL9')E;B`](&-H
M:6QD<F5N.PH@("`@("`@("`@("!F;W)E86-H("A.;V1E(&-H:6QD(#L at 8VAI
M;&1R96XI('L*("`@("`@("`@("`@("`@(&-H:6QD+G!A<F5N="`]('1H:7,[
M"B`@("`@("`@("`@('T*("`@("`@("!]"B`@("!]"B`@("`*("`@('!U8FQI
M8R!S=')I;F<@9V5T3F%M92 at I>PH@("`@("`@(')E='5R;B!N86UE.PH@("`@
M?0H*("`@('!U8FQI8R!.;V1E(&=E=$-H:6QD*&EN="!P;W-I=&EO;BE["B`@
M("`@("`@<F5T=7)N(&-H:6QD<F5N6W!O<VET:6]N73L*("`@('T*"B`@("!P
M=6)L:6, at 5&%G3F]D95M=(&=E=$-H:6QD<F5N*'-T<FEN9R!N86UE*7L*("`@
M("`@("!486=.;V1E6UT@;6%T8VAE<SL*("`@("`@("!F;W)E86-H("A.;V1E
M(&-H:6QD(#L at 8VAI;&1R96XI('L*("`@("`@("`@("`@875T;R!C:&EL9%1A
M9R`](&-A<W0H5&%G3F]D92D at 8VAI;&0["B`@("`@("`@("`@(&EF("AC:&EL
M9%1A9R`A:7,@;G5L;"`F)B!C:&EL9%1A9RYG971.86UE*"D@/3T@;F%M92D@
M>R`O+W1R:6-K>2P@<VEN8V4 at 8V%S="!I<R!U<V5D('1O(&-H96-K('1Y<&4*
M("`@("`@("`@("`@("`@(&UA=&-H97,@?CT at 8VAI;&1486<["B`@("`@("`@
M("`@('T*("`@("`@("!]"B`@("`@("`@<F5T=7)N(&UA=&-H97,["B`@("!]
M"@H@("`@<'5B;&EC('9O:60 at 861D0VAI;&0H3F]D92!N97=#:&EL9"E["B`@
M("`@("`@8VAI;&1R96X@?CT@;F5W0VAI;&0["B`@("`@("`@;F5W0VAI;&0N
M<&%R96YT(#T@=&AI<SL*("`@('T*"B`@("!P=6)L:6,@<W1R:6YG('1O4W1R
M:6YG*"E["B`@("`@("`@<W1R:6YG(&-O;G1E;G0@/2!N86UE('X@(B`B.PH@
M("`@("`@(&9O<F5A8V@@*$YO9&4 at 8VAI;&0 at .R!C:&EL9')E;BD@>PH@("`@
M("`@("`@("!C;VYT96YT('X](&-H:6QD+G1O4W1R:6YG*"D["B`@("`@("`@
M?0H@("`@("`@(&EF("AP87)E;G0@:7,@;G5L;"D@>PH@("`@("`@("`@("!R
M971U<FX at 8V]N=&5N=#L*("`@("`@("!]"B`@("`@("`@<F5T=7)N(");(B!^
M(&-O;G1E;G0@?B`B72(["B`@("!]"GT*"G!U8FQI8R!C;&%S<R!497AT3F]D
M92`Z($YO9&4@>PH@("`@<W1R:6YG(&-O;G1E;G0["@H@("`@=&AI<RAS=')I
M;F<@8V]N=&5N="E["B`@("`@("`@=&AI<RYC;VYT96YT(#T at 8V]N=&5N=#L*
M("`@('T*"B`@("!P=6)L:6,@<W1R:6YG('1O4W1R:6YG*"E["B`@("`@("`@
8<F5T=7)N(&-O;G1E;G0["B`@("!]"GT*
`
end
More information about the Digitalmars-d-learn
mailing list