Re: [PATCH] JSON_parser

From: Date: Fri, 25 May 2007 00:02:33 +0000
Subject: Re: [PATCH] JSON_parser
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-29732@lists.php.net to get a copy of this message
I think the current code is better and not to mention faster. Shorter code in this case does not mean better code. On 24-May-07, at 7:50 PM, Martin Majlis wrote:
Just small refactoring. Replacing self-made function with functions from standard headers. Index: JSON_parser.c =================================================================== RCS file: /repository/php-src/ext/json/JSON_parser.c,v retrieving revision 1.1.2.8 diff -u -u -r1.1.2.8 JSON_parser.c --- JSON_parser.c 24 May 2007 22:37:59 -0000 1.1.2.8 +++ JSON_parser.c 24 May 2007 23:41:11 -0000 @@ -29,6 +29,8 @@ #include "JSON_parser.h" #include <stdio.h> +#include <math.h> +#include <ctype.h> #define true 1 #define false 0 @@ -259,18 +261,10 @@ static int dehexchar(char c) {
-    if (c >= '0' && c <= '9')
-    {
-        return c - '0';
-    }
-    else if (c >= 'A' && c <= 'F')
-    {
-        return c - ('A' - 10);
-    }
-    else if (c >= 'a' && c <= 'f')
-    {
-        return c - ('a' - 10);
-    }
+    if (isxdigit(c))
+    {
+        return strtol(&c, NULL, 16);
+    }
    else
    {
        return -1;
--PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Ilia Alshanetsky

« previous php.internals (#29732) next »