diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-19 11:38:35 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-19 11:38:35 +0000 |
| commit | 6fb3ce9804a8886b013f0b342f9757121b39104d (patch) | |
| tree | debf1766e037db63f3579025a4619f32fc7bcc41 /lib | |
| parent | bf11d6ee76d5c696b58cd6080efbca38bf58e8fb (diff) | |
* lib/yaml/baseemitter.rb, lib/yaml/encoding.rb: performance
tuning around String#gsub.
* lib/yaml/tag.rb: Replace nodoc with stopdoc so Module methods get
documented.
* lib/yaml/store.rb (YAML::load): modified to support empty
database.
* lib/yaml/store.rb (YAML::Store::marshal_dump_supports_canonical_option?):
add a method to support faster PStore.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/yaml/baseemitter.rb | 2 | ||||
| -rw-r--r-- | lib/yaml/encoding.rb | 6 | ||||
| -rw-r--r-- | lib/yaml/store.rb | 20 | ||||
| -rw-r--r-- | lib/yaml/tag.rb | 7 |
4 files changed, 25 insertions, 10 deletions
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb index 1aef152749..a1992f498b 100644 --- a/lib/yaml/baseemitter.rb +++ b/lib/yaml/baseemitter.rb @@ -132,7 +132,7 @@ module YAML # Folding paragraphs within a column # def fold( value ) - value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s| + value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do $1 || $2 + ( $3 || "\n" ) end end diff --git a/lib/yaml/encoding.rb b/lib/yaml/encoding.rb index 37f5cfda64..57dc553606 100644 --- a/lib/yaml/encoding.rb +++ b/lib/yaml/encoding.rb @@ -10,8 +10,8 @@ module YAML def YAML.escape( value, skip = "" ) value.gsub( /\\/, "\\\\\\" ). gsub( /"/, "\\\"" ). - gsub( /([\x00-\x1f])/ ) do |x| - skip[x] || ESCAPES[ x.unpack("C")[0] ] + gsub( /([\x00-\x1f])/ ) do + skip[$&] || ESCAPES[ $&.unpack("C")[0] ] end end @@ -19,7 +19,7 @@ module YAML # Unescape the condenses escapes # def YAML.unescape( value ) - value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x| + value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { if $3 ["#$3".hex ].pack('U*') elsif $2 diff --git a/lib/yaml/store.rb b/lib/yaml/store.rb index 2ffa9554b9..e3a8e9fcdd 100644 --- a/lib/yaml/store.rb +++ b/lib/yaml/store.rb @@ -20,10 +20,24 @@ class YAML::Store < PStore end def load(content) - YAML::load(content) + table = YAML::load(content) + if table == false + {} + else + table + end + end + + def marshal_dump_supports_canonical_option? + false end - def load_file(file) - YAML::load(file) + EMPTY_MARSHAL_DATA = {}.to_yaml + EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA) + def empty_marshal_data + EMPTY_MARSHAL_DATA + end + def empty_marshal_checksum + EMPTY_MARSHAL_CHECKSUM end end diff --git a/lib/yaml/tag.rb b/lib/yaml/tag.rb index 56c3513bc0..0fb6bef9a0 100644 --- a/lib/yaml/tag.rb +++ b/lib/yaml/tag.rb @@ -51,11 +51,12 @@ module YAML end class Module + # :stopdoc: # Adds a taguri _tag_ to a class, used when dumping or loading the class # in YAML. See YAML::tag_class for detailed information on typing and # taguris. - def yaml_as( tag, sc = true ) # :nodoc: + def yaml_as( tag, sc = true ) verbose, $VERBOSE = $VERBOSE, nil class_eval <<-"end;", __FILE__, __LINE__+1 attr_writer :taguri @@ -79,12 +80,12 @@ class Module end # Transforms the subclass name into a name suitable for display # in a subclassed tag. - def yaml_tag_class_name # :nodoc: + def yaml_tag_class_name self.name end # Transforms the subclass name found in the tag into a Ruby # constant name. - def yaml_tag_read_class( name ) # :nodoc: + def yaml_tag_read_class( name ) name end end |
