summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2009-10-22 17:50:43 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2009-10-22 17:50:43 -0700
commit35fb005e028b42faff1ec0f01d84ed88d155df06 (patch)
treee2ed25d2feabf2614aed5b300efea297baa748df
parent3854df000780465f6e78b084732d5ab324be941e (diff)
downloadpsych-35fb005e028b42faff1ec0f01d84ed88d155df06.zip
speed improvement
-rw-r--r--.autotest7
-rw-r--r--Manifest.txt40
-rw-r--r--Rakefile2
-rw-r--r--lib/psych/scalar_scanner.rb17
-rw-r--r--lib/psych/visitors/to_ruby.rb54
5 files changed, 82 insertions, 38 deletions
diff --git a/.autotest b/.autotest
index 91445cd..ac7a24c 100644
--- a/.autotest
+++ b/.autotest
@@ -1,4 +1,5 @@
require "autotest/restart"
+require 'rbconfig'
Autotest.add_hook :initialize do |at|
at.find_directories = ARGV unless ARGV.empty?
@@ -7,11 +8,7 @@ end
Autotest.add_hook :run_command do |at|
at.unit_diff = 'cat'
- if ENV['ONENINE']
- system "rake1.9 compile"
- else
- system "rake compile"
- end
+ system "ruby -S rake compile"
end
Autotest.add_hook :ran_command do |at|
diff --git a/Manifest.txt b/Manifest.txt
index 0c84276..9225889 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -1,7 +1,41 @@
-History.txt
+.autotest
+CHANGELOG.rdoc
Manifest.txt
-README.txt
+README.rdoc
Rakefile
-bin/psych
+ext/psych/emitter.c
+ext/psych/emitter.h
+ext/psych/extconf.rb
+ext/psych/parser.c
+ext/psych/parser.h
+ext/psych/psych.c
+ext/psych/psych.h
lib/psych.rb
+lib/psych/emitter.rb
+lib/psych/handler.rb
+lib/psych/nodes/alias.rb
+lib/psych/nodes/document.rb
+lib/psych/nodes/mapping.rb
+lib/psych/nodes/node.rb
+lib/psych/nodes/scalar.rb
+lib/psych/nodes/sequence.rb
+lib/psych/nodes/stream.rb
+lib/psych/parser.rb
+lib/psych/ruby.rb
+lib/psych/scalar_scanner.rb
+lib/psych/tree_builder.rb
+lib/psych/visitable.rb
+lib/psych/visitors.rb
+lib/psych/visitors/emitter.rb
+lib/psych/visitors/to_ruby.rb
+lib/psych/visitors/visitor.rb
+lib/psych/visitors/yast_builder.rb
+test/psych/test_parser.rb
+test/psych/test_serialize_subclasses.rb
+test/psych/test_tree_builder.rb
test/test_psych.rb
+test/test_scalar_scanner.rb
+test/visitors/test_emitter.rb
+test/visitors/test_to_ruby.rb
+test/visitors/test_yast_builder.rb
+test/yaml/test_yaml.rb
diff --git a/Rakefile b/Rakefile
index b084f41..7068c40 100644
--- a/Rakefile
+++ b/Rakefile
@@ -19,6 +19,8 @@ Hoe.spec 'psych' do
extra_dev_deps << ['rake-compiler', '>= 0.4.1']
+ self.spec_extras = { :extensions => ["ext/psych/extconf.rb"] }
+
Rake::ExtensionTask.new "psych", spec do |ext|
ext.lib_dir = File.join(*['lib', 'psych', ENV['FAT_DIR']].compact)
end
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb
index a15096f..f6412eb 100644
--- a/lib/psych/scalar_scanner.rb
+++ b/lib/psych/scalar_scanner.rb
@@ -15,6 +15,17 @@ module Psych
return [:NULL, nil] if @string.empty?
case @string
+ when /^[A-Za-z~]/
+ case @string
+ when /^(null|~)$/i
+ [:NULL, nil]
+ when /^(y|yes|true|on)$/i
+ [:BOOLEAN, true]
+ when /^(n|no|false|off)$/i
+ [:BOOLEAN, false]
+ else
+ [:SCALAR, @string]
+ end
when TIME
[:TIME, @string]
when /^\d{4}-\d{1,2}-\d{1,2}$/
@@ -25,12 +36,6 @@ module Psych
[:NEGATIVE_INFINITY, -1 / 0.0]
when /^\.nan$/i
[:NAN, 0.0 / 0.0]
- when /^(null|~)$/i
- [:NULL, nil]
- when /^(y|yes|true|on)$/i
- [:BOOLEAN, true]
- when /^(n|no|false|off)$/i
- [:BOOLEAN, false]
when /^:.+/i
[:SYMBOL, @string.sub(/^:/, '').to_sym]
when /^[-+]?[1-9][0-9_]*(:[0-5]?[0-9])+$/
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 66fefef..dd8805b 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -28,6 +28,7 @@ module Psych
@st[o.anchor] = o.value if o.anchor
return o.value if o.quoted
+ return resolve_unknown(o) unless o.tag
case o.tag
when '!binary', 'tag:yaml.org,2002:binary'
@@ -61,30 +62,7 @@ module Psych
args.push(args.delete_at(1) == '...')
Range.new(*args)
else
- token = ScalarScanner.new(o.value).tokenize
-
- case token.first
- when :DATE
- require 'date'
- Date.strptime token.last, '%Y-%m-%d'
- when :TIME
- lexeme = token.last
-
- date, time = *(lexeme.split(/[ tT]/, 2))
- (yy, m, dd) = date.split('-').map { |x| x.to_i }
- md = time.match(/(\d+:\d+:\d+)(\.\d*)?\s*(Z|[-+]\d+(:\d\d)?)?/)
-
- (hh, mm, ss) = md[1].split(':').map { |x| x.to_i }
-
- time = Time.utc(yy, m, dd, hh, mm, ss)
-
- us = md[2] ? md[2].sub(/^\./, '').to_i : 0
-
- tz = (!md[3] || md[3] == 'Z') ? 0 : Integer(md[3].split(':').first)
- Time.at((time - (tz * 3600)).to_i, us)
- else
- token.last
- end
+ resolve_unknown o
end
end
@@ -178,6 +156,34 @@ module Psych
def visit_Psych_Nodes_Alias o
@st[o.anchor]
end
+
+ private
+ def resolve_unknown o
+ token = ScalarScanner.new(o.value).tokenize
+
+ case token.first
+ when :DATE
+ require 'date'
+ Date.strptime token.last, '%Y-%m-%d'
+ when :TIME
+ lexeme = token.last
+
+ date, time = *(lexeme.split(/[ tT]/, 2))
+ (yy, m, dd) = date.split('-').map { |x| x.to_i }
+ md = time.match(/(\d+:\d+:\d+)(\.\d*)?\s*(Z|[-+]\d+(:\d\d)?)?/)
+
+ (hh, mm, ss) = md[1].split(':').map { |x| x.to_i }
+
+ time = Time.utc(yy, m, dd, hh, mm, ss)
+
+ us = md[2] ? md[2].sub(/^\./, '').to_i : 0
+
+ tz = (!md[3] || md[3] == 'Z') ? 0 : Integer(md[3].split(':').first)
+ Time.at((time - (tz * 3600)).to_i, us)
+ else
+ token.last
+ end
+ end
end
end
end