improve speed by 7% by preprocessing the absolute xpath queries to perform path->dir
authorgc <gc>
Wed, 11 May 2005 20:37:32 +0000 (20:37 +0000)
committergc <gc>
Wed, 11 May 2005 20:37:32 +0000 (20:37 +0000)
bin/booh-backend

index 582272c0ee220b329b1cab4638b0b75eed25cee6..72f04254a0c0eb6d1c4340d2fc6f7f1e6491d8e3 100755 (executable)
@@ -376,6 +376,12 @@ end
 
 def walk_source_dir
 
+    #- preprocess the path->dir, rexml is very slow with that; we seem to improve speed by 7%
+    optxpath = {}
+    $xmldoc.elements.each('//dir') { |elem|
+        optxpath[elem.attributes['path']] = elem
+    }
+
     `find '#{$source}' -type d`.sort.each { |dir|
         dir.chomp!
         if File.basename(dir) =~ /^\./
@@ -389,7 +395,7 @@ def walk_source_dir
 
         #- place xml document on proper node if exists, else create
         newly_created_dir = false
-        xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
+        xmldir = optxpath[utf8(dir)]
         if $mode == 'use_config' || $mode == 'use_config_changetheme'
             if !xmldir
                 next
@@ -403,7 +409,7 @@ def walk_source_dir
                 if !xmldir
                     xmldir = $xmldoc.root
                 end
-                xmldir = xmldir.add_element 'dir', { 'path' => utf8(dir) }
+                xmldir = optxpath[utf8(dir)] = xmldir.add_element('dir', { 'path' => utf8(dir) })
             end
         end
 
@@ -682,7 +688,7 @@ def walk_source_dir
 
     `find '#{$source}' -type d`.each { |dir|
         dir.chomp!
-        xmldir = $xmldoc.elements["//dir[@path='#{utf8(dir)}']"]
+        xmldir = optxpath[utf8(dir)]
         if !xmldir
             next
         end