ruby-changes:4589
From: ko1@a...
Date: Sat, 19 Apr 2008 20:38:49 +0900 (JST)
Subject: [ruby-changes:4589] knu - Ruby:r16083 (ruby_1_8): * lib/yaml/baseemitter.rb, lib/yaml/encoding.rb: performance
knu 2008-04-19 20:38:35 +0900 (Sat, 19 Apr 2008)
New Revision: 16083
Added files:
branches/ruby_1_8/test/yaml/test_yamlstore.rb
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/lib/yaml/baseemitter.rb
branches/ruby_1_8/lib/yaml/encoding.rb
branches/ruby_1_8/lib/yaml/store.rb
branches/ruby_1_8/lib/yaml/tag.rb
Log:
* 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.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/yaml/encoding.rb?r1=16083&r2=16082&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/yaml/baseemitter.rb?r1=16083&r2=16082&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16083&r2=16082&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/yaml/tag.rb?r1=16083&r2=16082&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/yaml/store.rb?r1=16083&r2=16082&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/yaml/test_yamlstore.rb?revision=16083&view=markup
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16082)
+++ ruby_1_8/ChangeLog (revision 16083)
@@ -1,3 +1,17 @@
+Sat Apr 19 20:35:02 2008 Akinori MUSHA <knu@i...>
+
+ * 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.
+
Sat Apr 19 20:16:52 2008 Akinori MUSHA <knu@i...>
* lib/yaml/types.rb: Likewise, pass self to YAML::quick_emit;
Index: ruby_1_8/lib/yaml/encoding.rb
===================================================================
--- ruby_1_8/lib/yaml/encoding.rb (revision 16082)
+++ ruby_1_8/lib/yaml/encoding.rb (revision 16083)
@@ -10,8 +10,8 @@
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 @@
# 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
Index: ruby_1_8/lib/yaml/store.rb
===================================================================
--- ruby_1_8/lib/yaml/store.rb (revision 16082)
+++ ruby_1_8/lib/yaml/store.rb (revision 16083)
@@ -20,10 +20,24 @@
end
def load(content)
- YAML::load(content)
+ table = YAML::load(content)
+ if table == false
+ {}
+ else
+ table
+ end
end
- def load_file(file)
- YAML::load(file)
+ def marshal_dump_supports_canonical_option?
+ false
end
+
+ 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
Index: ruby_1_8/lib/yaml/baseemitter.rb
===================================================================
--- ruby_1_8/lib/yaml/baseemitter.rb (revision 16082)
+++ ruby_1_8/lib/yaml/baseemitter.rb (revision 16083)
@@ -132,7 +132,7 @@
# 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
Index: ruby_1_8/lib/yaml/tag.rb
===================================================================
--- ruby_1_8/lib/yaml/tag.rb (revision 16082)
+++ ruby_1_8/lib/yaml/tag.rb (revision 16083)
@@ -51,11 +51,12 @@
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 @@
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
Index: ruby_1_8/test/yaml/test_yamlstore.rb
===================================================================
--- ruby_1_8/test/yaml/test_yamlstore.rb (revision 0)
+++ ruby_1_8/test/yaml/test_yamlstore.rb (revision 16083)
@@ -0,0 +1,74 @@
+require 'test/unit'
+require 'yaml/store'
+
+class YAMLStoreTest < Test::Unit::TestCase
+ def setup
+ @yamlstore_file = "yamlstore.tmp.#{Process.pid}"
+ @yamlstore = YAML::Store.new(@yamlstore_file)
+ end
+
+ def teardown
+ File.unlink(@yamlstore_file) rescue nil
+ end
+
+ def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
+ @yamlstore.transaction(true) do
+ assert_nil @yamlstore[:foo]
+ assert_nil @yamlstore[:bar]
+ end
+ end
+
+ def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
+ @yamlstore.transaction do
+ assert_nil @yamlstore[:foo]
+ assert_nil @yamlstore[:bar]
+ end
+ end
+
+ def test_data_should_be_loaded_correctly_when_in_readonly_mode
+ @yamlstore.transaction do
+ @yamlstore[:foo] = "bar"
+ end
+ @yamlstore.transaction(true) do
+ assert_equal "bar", @yamlstore[:foo]
+ end
+ end
+
+ def test_data_should_be_loaded_correctly_when_in_readwrite_mode
+ @yamlstore.transaction do
+ @yamlstore[:foo] = "bar"
+ end
+ @yamlstore.transaction do
+ assert_equal "bar", @yamlstore[:foo]
+ end
+ end
+
+ def test_changes_after_commit_are_discarded
+ @yamlstore.transaction do
+ @yamlstore[:foo] = "bar"
+ @yamlstore.commit
+ @yamlstore[:foo] = "baz"
+ end
+ @yamlstore.transaction(true) do
+ assert_equal "bar", @yamlstore[:foo]
+ end
+ end
+
+ def test_changes_are_not_written_on_abort
+ @yamlstore.transaction do
+ @yamlstore[:foo] = "bar"
+ @yamlstore.abort
+ end
+ @yamlstore.transaction(true) do
+ assert_nil @yamlstore[:foo]
+ end
+ end
+
+ def test_writing_inside_readonly_transaction_raises_error
+ assert_raise(PStore::Error) do
+ @yamlstore.transaction(true) do
+ @yamlstore[:foo] = "bar"
+ end
+ end
+ end
+end
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/