[svn:parrot] r46401 - in trunk: src/pmc t/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sat May 8 08:17:03 UTC 2010


Author: bacek
Date: Sat May  8 08:17:02 2010
New Revision: 46401
URL: https://trac.parrot.org/parrot/changeset/46401

Log:
Drop str->hashval in StringBuilder.set_string_native instead of get_string

Modified:
   trunk/src/pmc/stringbuilder.pmc
   trunk/t/pmc/stringbuilder.t

Modified: trunk/src/pmc/stringbuilder.pmc
==============================================================================
--- trunk/src/pmc/stringbuilder.pmc	Sat May  8 07:59:11 2010	(r46400)
+++ trunk/src/pmc/stringbuilder.pmc	Sat May  8 08:17:02 2010	(r46401)
@@ -103,9 +103,7 @@
     VTABLE STRING *get_string() {
         STRING *buffer, *retv;
         GET_ATTR_buffer(INTERP, SELF, buffer);
-        retv = Parrot_str_clone(INTERP, buffer);
-        retv->hashval = 0; /* hash is invalid */
-        return retv;
+        return Parrot_str_clone(INTERP, buffer);
     }
 
 /*
@@ -200,7 +198,10 @@
 
 */
     VTABLE void set_string_native(STRING *s) {
-        SET_ATTR_buffer(INTERP, SELF, Parrot_str_clone(INTERP, s));
+        STRING * tmp = Parrot_str_clone(INTERP, s);
+        /* Unset hashval. We update this string all the time */
+        tmp->hashval = 0;
+        SET_ATTR_buffer(INTERP, SELF, tmp);
     }
 
 

Modified: trunk/t/pmc/stringbuilder.t
==============================================================================
--- trunk/t/pmc/stringbuilder.t	Sat May  8 07:59:11 2010	(r46400)
+++ trunk/t/pmc/stringbuilder.t	Sat May  8 08:17:02 2010	(r46401)
@@ -20,13 +20,14 @@
 .sub 'main' :main
     .include 'test_more.pir'
 
-    plan(21)
+    plan(23)
     test_create()               # 2 tests
     test_push_string()          # 9 tests
     test_push_pmc()             # 4 tests
     test_push_string_unicode()  # 1 test
     test_i_concatenate()        # 1 test
     test_set_string_native()    # 3 tests
+    test_set_string_native_with_hash()    # 2 tests
 
     # END_OF_TESTS
 .end
@@ -160,6 +161,29 @@
 
 .end
 
+.sub 'test_set_string_native_with_hash'
+    .local pmc sb, hash
+    sb   = new ["StringBuilder"]
+    hash = new ['Hash']
+
+    $S0 = "foo"
+    hash[$S0] = "foo"
+    sb   = $S0
+    # Used later
+    $S0  = sb
+
+    sb .= "bar"
+    $S1  = sb
+    hash[$S1] = $S1
+
+    $S99 = hash[$S0]
+    is ( $S99, "foo", "First string stored in hash" )
+
+    $S99 = hash[$S1]
+    is ( $S99, "foobar", "Second string stored in hash" )
+
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100


More information about the parrot-commits mailing list