gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/asobj/Global.cpp


From: Martin Guy
Subject: [Gnash-commit] gnash ChangeLog server/asobj/Global.cpp
Date: Thu, 01 Feb 2007 18:08:16 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Martin Guy <martinwguy> 07/02/01 18:08:15

Modified files:
        .              : ChangeLog 
        server/asobj   : Global.cpp 

Log message:
        Rewrite lame code in straing conversion: replace insane case statement 
and
        avoid unnecessary use of floating point

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2219&r2=1.2220
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Global.cpp?cvsroot=gnash&r1=1.35&r2=1.36

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2219
retrieving revision 1.2220
diff -u -b -r1.2219 -r1.2220
--- ChangeLog   1 Feb 2007 17:47:17 -0000       1.2219
+++ ChangeLog   1 Feb 2007 18:08:15 -0000       1.2220
@@ -1,5 +1,11 @@
 2007-02-01 Martin Guy <address@hidden>
 
+       * server/asobj/Global.cpp: Rewrite lame code in string conversions:
+         remove insane case statement and avoid unnecessary use of floating
+         point
+
+2007-02-01 Martin Guy <address@hidden>
+
        * testsuite/actionscript.all/Global.as: fix bug in parseInt octal test
          (now succeeds)
 

Index: server/asobj/Global.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Global.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- server/asobj/Global.cpp     27 Jan 2007 16:55:05 -0000      1.35
+++ server/asobj/Global.cpp     1 Feb 2007 18:08:15 -0000       1.36
@@ -18,7 +18,7 @@
 
 // Implementation of the Global ActionScript Object
 
-/* $Id: Global.cpp,v 1.35 2007/01/27 16:55:05 tgc Exp $ */
+/* $Id: Global.cpp,v 1.36 2007/02/01 18:08:15 martinwguy Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -127,13 +127,14 @@
     fn.result->set_bool(fn.arg(0).is_finite());
 }
 
+/// \brief Decode a string from URL-encoded format
+//        converting all hexadecimal sequences to ASCII characters.
 static void
 as_global_unescape(const fn_call& fn)
 {
     assert(fn.nargs == 1);
 
     string input = fn.arg(0).to_string();
-    string insertst;
     int hexcode;
 
     for (unsigned int i=0;i<input.length();)
@@ -154,6 +155,10 @@
                        hexcode += (input[i+2] - 'A' + 10);
 
                    input.erase(i,3);
+#if 1
+                   input.insert(i,string(1,(char)hexcode));
+#else
+                   string insertst;
                                
                    switch (hexcode)
                        {
@@ -239,6 +244,7 @@
                              return;
                        }
                    input.insert(i,insertst);
+#endif
                }
            else
                i++;
@@ -275,8 +281,7 @@
     char *input_buffer = new char[strlen(fn.arg(0).to_string())+1];
     char *input = input_buffer;
     strcpy(input,fn.arg(0).to_string());
-    double base;
-    int result = 0, i;
+    int base;
     bool bNegative;
 
     // Skip leading whitespace
@@ -292,7 +297,7 @@
        bNegative = false;
 
     // Convert the string to uppercase
-    for (i=0;i<int(strlen(input));i++)
+    for (int i=0;i<int(strlen(input));i++)
        input[i] = toupper(input[i]);
 
     // if we were sent a second argument, that's our base
@@ -304,21 +309,26 @@
     else if (strlen(input) > 2 && input[0] == '0' && input[1] == 'X'
             && (isdigit(input[2]) || (input[2] >= 'A' && input[2] <= 'F')))
        {
-           base = 16.0;        // the base is 16
+           base = 16;  // the base is 16
            input = input + 2; // skip the leading "0x"
        }
     // if the string starts with "0" then an octal digit
     else if (strlen(input) > 1 && input[0] == '0' &&
             (input[1] >= '0' && input[1] <= '7'))
        {
-           base = 8.0;
+           base = 8;
            input++; // skip the leading '0'
        }
     else
        // default base is 10
-       base = 10.0;
+       base = 10;
 
-    assert (base >= 2 && base <= 36);
+    if (base < 2 || base > 36)
+       {
+           fn.result->set_nan();
+           delete [] input_buffer;
+           return;
+       }
 
     int numdigits = 0;
 
@@ -337,9 +347,10 @@
            return;
        }
 
-    for (i=0;i<numdigits;i++)
+    int result = 0;
+    for (int i=0;i<numdigits;i++)
        {
-               result += digits.find(input[i]) * (int)pow(base, numdigits - i 
- 1);
+           result = result * base + digits.find(input[i]);
        }
 
     if (bNegative)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]