diff options
| author | Markus Roberts <Markus@reality.com> | 2010-04-29 14:20:44 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2010-05-02 11:40:24 +1000 |
| commit | 6739bab16e3126ccba13f025a4b47d38f15c1f67 (patch) | |
| tree | 3ca00385b34d592656bc6db1ccd26be655737679 /lib/puppet/parser | |
| parent | b0e3c61a8b3b28c9214ba4aa986f533f61831daf (diff) | |
| download | puppet-6739bab16e3126ccba13f025a4b47d38f15c1f67.tar.gz puppet-6739bab16e3126ccba13f025a4b47d38f15c1f67.tar.xz puppet-6739bab16e3126ccba13f025a4b47d38f15c1f67.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.rb | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index bb4fdf9c9..2c0943d53 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -262,16 +262,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 find_string_token |
