]> granicus.if.org Git - php/commitdiff
Inline IS_LONG value calculation and avoid strtol() call.
authorDmitry Stogov <dmitry@zend.com>
Tue, 5 May 2015 08:09:18 +0000 (11:09 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 5 May 2015 08:09:18 +0000 (11:09 +0300)
Zend/zend_operators.c

index 2c80432dab5dde00ae368471af9610d4e5096ca5..e384031ddb315518118c9b0fa0a3f9af2fc96044 100644 (file)
@@ -2624,6 +2624,8 @@ ZEND_API zend_uchar ZEND_FASTCALL _is_numeric_string_ex(const char *str, size_t
        int digits = 0, dp_or_e = 0;
        double local_dval = 0.0;
        zend_uchar type;
+       zend_long tmp_lval = 0;
+       int neg = 0;
 
        if (!length) {
                return 0;
@@ -2641,7 +2643,10 @@ ZEND_API zend_uchar ZEND_FASTCALL _is_numeric_string_ex(const char *str, size_t
        }
        ptr = str;
 
-       if (*ptr == '-' || *ptr == '+') {
+       if (*ptr == '-') {
+               neg = 1;
+               ptr++;
+       } else if (*ptr == '+') {
                ptr++;
        }
 
@@ -2657,6 +2662,7 @@ ZEND_API zend_uchar ZEND_FASTCALL _is_numeric_string_ex(const char *str, size_t
                for (type = IS_LONG; !(digits >= MAX_LENGTH_OF_LONG && (dval || allow_errors == 1)); digits++, ptr++) {
 check_digits:
                        if (ZEND_IS_DIGIT(*ptr)) {
+                               tmp_lval = tmp_lval * 10 + (*ptr) - '0';
                                continue;
                        } else if (*ptr == '.' && dp_or_e < 1) {
                                goto process_double;
@@ -2723,7 +2729,10 @@ process_double:
                }
 
                if (lval) {
-                       *lval = ZEND_STRTOL(str, NULL, 10);
+                       if (neg) {
+                               tmp_lval = -tmp_lval;
+                       }
+                       *lval = tmp_lval;
                }
 
                return IS_LONG;