summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-04-29 14:20:44 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit088c80148d1fa082ac6f79023739bc268d096bc0 (patch)
tree6caf72cc73206ef52de412eaa5865615d5bd4ff7 /lib/puppet/parser
parentcd06b877cd97edb26551d9c30c399d666603e586 (diff)
downloadpuppet-088c80148d1fa082ac6f79023739bc268d096bc0.tar.gz
puppet-088c80148d1fa082ac6f79023739bc268d096bc0.tar.xz
puppet-088c80148d1fa082ac6f79023739bc268d096bc0.zip
Fix for #3558 -- source file reading speedup
It's about 10x faster to read the whole file than to read each line and concatenate them (actually, it's O(n) vs. O(n^2), so the exact speedup depends on the file size).
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/lexer.rb8
1 files changed, 1 insertions, 7 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 2a1f88e44..f13a85f35 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -286,16 +286,10 @@ class Puppet::Parser::Lexer
return array
end
- # this is probably pretty damned inefficient...
- # it'd be nice not to have to load the whole file first...
def file=(file)
@file = file
@line = 1
- File.open(file) { |of|
- str = ""
- of.each { |line| str += line }
- @scanner = StringScanner.new(str)
- }
+ @scanner = StringScanner.new(File.read(file))
end
def shift_token