Skip to content
Browse files

Minor optimizations using local variables

  • Loading branch information...
1 parent b7101a6 commit fd13812388adf3c4a728b3b6bd24c21e8dc013ff @jskorpan jskorpan committed Apr 22, 2012
Showing with 43 additions and 31 deletions.
  1. +43 −31 lib/ultrajsondec.c
View
74 lib/ultrajsondec.c
@@ -86,10 +86,11 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
int decimalCount = 0;
double frcValue = 0.0;
double expValue;
+ char *offset = ds->start;
- if (*(ds->start) == '-')
+ if (*(offset) == '-')
{
- ds->start ++;
+ offset ++;
intNeg = -1;
}
@@ -98,7 +99,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
while (1)
{
- chr = (int) (unsigned char) *(ds->start);
+ chr = (int) (unsigned char) *(offset);
switch (chr)
{
@@ -119,17 +120,17 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
#else
intValue = intValue * 10LL + (JSLONG) (chr - 48);
#endif
- ds->start ++;
+ offset ++;
break;
case '.':
- ds->start ++;
+ offset ++;
goto DECODE_FRACTION;
break;
case 'e':
case 'E':
- ds->start ++;
+ offset ++;
goto DECODE_EXPONENT;
break;
@@ -142,6 +143,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
BREAK_INT_LOOP:
ds->lastType = JT_INT;
+ ds->start = offset;
//If input string is LONGLONG_MIN here the value is already negative so we should not flip it
@@ -177,7 +179,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
frcValue = 0.0;
while (1)
{
- chr = (int) (unsigned char) *(ds->start);
+ chr = (int) (unsigned char) *(offset);
switch (chr)
{
@@ -196,12 +198,12 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
frcValue = frcValue * 10.0 + (double) (chr - 48);
decimalCount ++;
}
- ds->start ++;
+ offset ++;
break;
case 'e':
case 'E':
- ds->start ++;
+ offset ++;
goto DECODE_EXPONENT;
break;
@@ -219,28 +221,29 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
//FIXME: Check for arithemtic overflow here
ds->lastType = JT_DOUBLE;
+ ds->start = offset;
RETURN_JSOBJ_NULLCHECK(ds->dec->newDouble (createDouble( (double) intNeg, (double) intValue, frcValue, decimalCount)));
DECODE_EXPONENT:
expNeg = 1.0;
- if (*(ds->start) == '-')
+ if (*(offset) == '-')
{
expNeg = -1.0;
- ds->start ++;
+ offset ++;
}
else
- if (*(ds->start) == '+')
+ if (*(offset) == '+')
{
expNeg = +1.0;
- ds->start ++;
+ offset ++;
}
expValue = 0.0;
while (1)
{
- chr = (int) (unsigned char) *(ds->start);
+ chr = (int) (unsigned char) *(offset);
switch (chr)
{
@@ -255,7 +258,7 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
case '8':
case '9':
expValue = expValue * 10.0 + (double) (chr - 48);
- ds->start ++;
+ offset ++;
break;
default:
@@ -276,21 +279,24 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric ( struct DecoderState *ds)
//FIXME: Check for arithemtic overflow here
ds->lastType = JT_DOUBLE;
+ ds->start = offset;
RETURN_JSOBJ_NULLCHECK(ds->dec->newDouble (createDouble( (double) intNeg, (double) intValue , frcValue, decimalCount) * pow(10.0, expValue * expNeg)));
}
FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_true ( struct DecoderState *ds)
{
- ds->start ++;
+ char *offset = ds->start;
+ offset ++;
- if (*(ds->start++) != 'r')
+ if (*(offset++) != 'r')
goto SETERROR;
- if (*(ds->start++) != 'u')
+ if (*(offset++) != 'u')
goto SETERROR;
- if (*(ds->start++) != 'e')
+ if (*(offset++) != 'e')
goto SETERROR;
ds->lastType = JT_TRUE;
+ ds->start = offset;
RETURN_JSOBJ_NULLCHECK(ds->dec->newTrue());
SETERROR:
@@ -299,18 +305,20 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_true ( struct DecoderState *ds)
FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_false ( struct DecoderState *ds)
{
- ds->start ++;
+ char *offset = ds->start;
+ offset ++;
- if (*(ds->start++) != 'a')
+ if (*(offset++) != 'a')
goto SETERROR;
- if (*(ds->start++) != 'l')
+ if (*(offset++) != 'l')
goto SETERROR;
- if (*(ds->start++) != 's')
+ if (*(offset++) != 's')
goto SETERROR;
- if (*(ds->start++) != 'e')
+ if (*(offset++) != 'e')
goto SETERROR;
ds->lastType = JT_FALSE;
+ ds->start = offset;
RETURN_JSOBJ_NULLCHECK(ds->dec->newFalse());
SETERROR:
@@ -321,16 +329,18 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_false ( struct DecoderState *ds)
FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_null ( struct DecoderState *ds)
{
- ds->start ++;
+ char *offset = ds->start;
+ offset ++;
- if (*(ds->start++) != 'u')
+ if (*(offset++) != 'u')
goto SETERROR;
- if (*(ds->start++) != 'l')
+ if (*(offset++) != 'l')
goto SETERROR;
- if (*(ds->start++) != 'l')
+ if (*(offset++) != 'l')
goto SETERROR;
ds->lastType = JT_NULL;
+ ds->start = offset;
RETURN_JSOBJ_NULLCHECK(ds->dec->newNull());
SETERROR:
@@ -339,18 +349,21 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_null ( struct DecoderState *ds)
FASTCALL_ATTR void FASTCALL_MSVC SkipWhitespace(struct DecoderState *ds)
{
+ char *offset = ds->start;
+
while (1)
{
- switch (*ds->start)
+ switch (*offset)
{
case ' ':
case '\t':
case '\r':
case '\n':
- ds->start ++;
+ offset ++;
break;
default:
+ ds->start = offset;
return;
}
}
@@ -420,7 +433,6 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_string ( struct DecoderState *ds)
}
escOffset = ds->escStart;
-
inputOffset = ds->start;
while(1)

0 comments on commit fd13812

Please sign in to comment.
Something went wrong with that request. Please try again.