[svn:parrot] r46725 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Mon May 17 08:21:47 UTC 2010
Author: bacek
Date: Mon May 17 08:21:46 2010
New Revision: 46725
URL: https://trac.parrot.org/parrot/changeset/46725
Log:
Add StringBuilder.get_string_length method to fetch string length without cloning buffer
Modified:
trunk/src/pmc/stringbuilder.pmc
trunk/t/pmc/stringbuilder.t
Modified: trunk/src/pmc/stringbuilder.pmc
==============================================================================
--- trunk/src/pmc/stringbuilder.pmc Mon May 17 05:57:38 2010 (r46724)
+++ trunk/src/pmc/stringbuilder.pmc Mon May 17 08:21:46 2010 (r46725)
@@ -380,6 +380,22 @@
RETURN(PMC *SELF);
}
+/*
+=item C<INTVAL get_string_length()>
+
+Returns length of currently built string.
+
+=cut
+*/
+
+ METHOD get_string_length() {
+ STRING *buffer;
+ INTVAL length;
+ GET_ATTR_buffer(INTERP, SELF, buffer);
+ length = Parrot_str_length(INTERP, buffer);
+ RETURN(INTVAL length);
+ }
+
/*
Modified: trunk/t/pmc/stringbuilder.t
==============================================================================
--- trunk/t/pmc/stringbuilder.t Mon May 17 05:57:38 2010 (r46724)
+++ trunk/t/pmc/stringbuilder.t Mon May 17 08:21:46 2010 (r46725)
@@ -68,6 +68,9 @@
$I0 = sb
is( $I0, 128, "... and capacity still 128" )
+ $I0 = sb.'get_string_length'()
+ is( $I0, 6, "... and string length is correct")
+
# Push large string which will cause reallocate
$S99 = repeat "x", 128
push sb, $S99
More information about the parrot-commits
mailing list