Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

speed improvement

  • Loading branch information...
commit 35fb005e028b42faff1ec0f01d84ed88d155df06 1 parent 3854df0
Aaron Patterson authored
7 .autotest
View
@@ -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|
40 Manifest.txt
View
@@ -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
2  Rakefile
View
@@ -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
17 lib/psych/scalar_scanner.rb
View
@@ -15,6 +15,17 @@ def tokenize
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 @@ def tokenize
[: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])+$/
54 lib/psych/visitors/to_ruby.rb
View
@@ -28,6 +28,7 @@ def visit_Psych_Nodes_Scalar o
@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 @@ def visit_Psych_Nodes_Scalar o
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 @@ def visit_Psych_Nodes_Stream o
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
Please sign in to comment.
Something went wrong with that request. Please try again.