[svn:parrot] r46516 - trunk/src/string/charset

jimmy at svn.parrot.org jimmy at svn.parrot.org
Tue May 11 15:13:18 UTC 2010


Author: jimmy
Date: Tue May 11 15:13:17 2010
New Revision: 46516
URL: https://trac.parrot.org/parrot/changeset/46516

Log:
calculate string length before loop, it avoids calculating string length very loop.

Modified:
   trunk/src/string/charset/ascii.c
   trunk/src/string/charset/iso-8859-1.c
   trunk/src/string/charset/unicode.c

Modified: trunk/src/string/charset/ascii.c
==============================================================================
--- trunk/src/string/charset/ascii.c	Tue May 11 15:12:33 2010	(r46515)
+++ trunk/src/string/charset/ascii.c	Tue May 11 15:13:17 2010	(r46516)
@@ -649,9 +649,10 @@
     ASSERT_ARGS(validate)
     INTVAL      offset;
     String_iter iter;
+    const INTVAL length = Parrot_str_length(interp, src);
 
     ENCODING_ITER_INIT(interp, src, &iter);
-    for (offset = 0; offset < Parrot_str_length(interp, src); ++offset) {
+    for (offset = 0; offset < length; ++offset) {
         const UINTVAL codepoint = iter.get_and_advance(interp, &iter);
         if (codepoint >= 0x80)
             return 0;

Modified: trunk/src/string/charset/iso-8859-1.c
==============================================================================
--- trunk/src/string/charset/iso-8859-1.c	Tue May 11 15:12:33 2010	(r46515)
+++ trunk/src/string/charset/iso-8859-1.c	Tue May 11 15:13:17 2010	(r46516)
@@ -526,8 +526,9 @@
 {
     ASSERT_ARGS(validate)
     INTVAL offset;
+    const INTVAL length =  Parrot_str_length(interp, src);
 
-    for (offset = 0; offset < Parrot_str_length(interp, src); ++offset) {
+    for (offset = 0; offset < length; ++offset) {
         const UINTVAL codepoint = ENCODING_GET_CODEPOINT(interp, src, offset);
         if (codepoint >= 0x100)
             return 0;

Modified: trunk/src/string/charset/unicode.c
==============================================================================
--- trunk/src/string/charset/unicode.c	Tue May 11 15:12:33 2010	(r46515)
+++ trunk/src/string/charset/unicode.c	Tue May 11 15:13:17 2010	(r46516)
@@ -718,9 +718,10 @@
     ASSERT_ARGS(validate)
     INTVAL      offset;
     String_iter iter;
+    const INTVAL length = Parrot_str_length(interp, src);
 
     ENCODING_ITER_INIT(interp, src, &iter);
-    for (offset = 0; offset < Parrot_str_length(interp, src); ++offset) {
+    for (offset = 0; offset < length; ++offset) {
         const UINTVAL codepoint = iter.get_and_advance(interp, &iter);
         /* Check for Unicode non-characters */
         if (codepoint >= 0xfdd0


More information about the parrot-commits mailing list