diff Lib/IMPL/DOM/XMLReader.pm @ 37:c2e7f7c96bcd

performance improvements, DOM reworked (a little)
author Sergey
date Mon, 23 Nov 2009 00:59:06 +0300
parents 65a7bb156fb7
children 16ada169ca75
line wrap: on
line diff
--- a/Lib/IMPL/DOM/XMLReader.pm	Fri Nov 20 16:48:08 2009 +0300
+++ b/Lib/IMPL/DOM/XMLReader.pm	Mon Nov 23 00:59:06 2009 +0300
@@ -12,6 +12,8 @@
 BEGIN {
     public _direct property Navigator => prop_get | owner_set;
     private _direct property _current => prop_all;
+    private _direct property _text => prop_all;
+    private _direct property _textHistory => prop_all;
 }
 
 sub Parse {
@@ -33,9 +35,9 @@
     
     my $parser = new XML::Parser(
         Handlers => {
-            Start => sub {shift; goto &_OnStart($this,@_)},
-            End => sub {shift; goto &_OnEnd($this,@_)},
-            Char => sub {shift; goto &_OnChar($this,@_)}
+            Start => sub {shift; unshift @_, $this; goto &_OnBegin;},
+            End => sub {shift; unshift @_, $this; goto &_OnEnd;},
+            Char => sub {shift; unshift @_, $this; goto &_OnChar;}
         }
     );
     
@@ -46,19 +48,22 @@
 sub _OnBegin {
     my ($this,$element,%attrs) = @_;
     
+    push @{$this->{$_textHistory}},$this->{$_text};
+    $this->{$_text} = "";
     $this->{$_current} = $this->Navigator->NavigateCreate($element,%attrs);
 }
 
 sub _OnEnd {
     my ($this,$element) = @_;
     
-    $this->{$_current} = $this->Back;
+    $this->{$_current}->nodeValue($this->{$_text}) if length $this->{$_text};
+    $this->{$_text} = pop @{$this->{$_textHistory}};
+    $this->{$_current} = $this->Navigator->Back;
 }
 
 sub _OnChar {
     my ($this,$val) = @_;
-    
-    $this->{$_current}->nodeValue($this->{$_current}->nodeValue . $val);
+    $this->{$_text} .= $val;
 }
 
 1;