Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reverted change caef3ee of using compile-time constants for JSON toke…

…ns due to extra steps required to build from source.
commit 24c6c16aecbf0d8fcc043ae671e689b0d4b4c559 1 parent cc66f99
@darronschall darronschall authored
View
36 build/build.xml
@@ -64,23 +64,6 @@
<source-path path-element="${src.dir}" />
<source-path path-element="${test.src.dir}" />
- <!--
- Define JSON Constants
- -->
- <define name="JSON_TOKEN::UNKNOWN" value="-1" />
- <define name="JSON_TOKEN::COMMA" value="0" />
- <define name="JSON_TOKEN::LEFT_BRACE" value="1" />
- <define name="JSON_TOKEN::RIGHT_BRACE" value="2" />
- <define name="JSON_TOKEN::LEFT_BRACKET" value="3" />
- <define name="JSON_TOKEN::RIGHT_BRACKET" value="4" />
- <define name="JSON_TOKEN::COLON" value="6" />
- <define name="JSON_TOKEN::TRUE" value="7" />
- <define name="JSON_TOKEN::FALSE" value="8" />
- <define name="JSON_TOKEN::NULL" value="9" />
- <define name="JSON_TOKEN::STRING" value="10" />
- <define name="JSON_TOKEN::NUMBER" value="11" />
- <define name="JSON_TOKEN::NAN" value="12" />
-
<!-- The TestRunner needs the flexunit libraries in the build/libs folder -->
<library-path dir="${build.libs.dir}" append="true">
<include name="*.swc" />
@@ -122,23 +105,6 @@
<load-config filename="${FLEX_HOME}/frameworks/air-config.xml" />
- <!--
- Define JSON Constants
- -->
- <define name="JSON_TOKEN::UNKNOWN" value="-1" />
- <define name="JSON_TOKEN::COMMA" value="0" />
- <define name="JSON_TOKEN::LEFT_BRACE" value="1" />
- <define name="JSON_TOKEN::RIGHT_BRACE" value="2" />
- <define name="JSON_TOKEN::LEFT_BRACKET" value="3" />
- <define name="JSON_TOKEN::RIGHT_BRACKET" value="4" />
- <define name="JSON_TOKEN::COLON" value="6" />
- <define name="JSON_TOKEN::TRUE" value="7" />
- <define name="JSON_TOKEN::FALSE" value="8" />
- <define name="JSON_TOKEN::NULL" value="9" />
- <define name="JSON_TOKEN::STRING" value="10" />
- <define name="JSON_TOKEN::NUMBER" value="11" />
- <define name="JSON_TOKEN::NAN" value="12" />
-
<source-path path-element="${src.dir}" />
<include-sources dir="${src.dir}" includes="*" />
</compc>
@@ -162,8 +128,6 @@
<!-- Include the library name in the window title -->
<arg line="-window-title 'Adobe ActionScript 3.0 Core Library - ${library.name}' "/>
- <!-- Define JSON Constants -->
- <arg line="-define+=JSON_TOKEN::UNKNOWN,-1 -define+=JSON_TOKEN::COMMA,0 -define+=JSON_TOKEN::LEFT_BRACE,1 -define+=JSON_TOKEN::RIGHT_BRACE,2 -define+=JSON_TOKEN::LEFT_BRACKET,3 -define+=JSON_TOKEN::RIGHT_BRACKET,4 -define+=JSON_TOKEN::COLON,6 -define+=JSON_TOKEN::TRUE,7 -define+=JSON_TOKEN::FALSE,8 -define+=JSON_TOKEN::NULL,9 -define+=JSON_TOKEN::STRING,10 -define+=JSON_TOKEN::NUMBER,11 -define+=JSON_TOKEN::NAN,12" />
</java>
<echo message="Documentation has been created in ${docs.dir}" />
View
44 src/com/adobe/serialization/json/JSONDecoder.as
@@ -140,20 +140,20 @@ package com.adobe.serialization.json
nextValidToken();
// check to see if we have an empty array
- if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
{
// we're done reading the array, so return it
return a;
}
// in non-strict mode an empty array is also a comma
// followed by a right bracket
- else if ( !strict && token.type == JSON_TOKEN::COMMA )
+ else if ( !strict && token.type == JSONTokenType.COMMA )
{
// move past the comma
nextValidToken();
// check to see if we're reached the end of the array
- if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
{
return a;
}
@@ -173,12 +173,12 @@ package com.adobe.serialization.json
// after the value there should be a ] or a ,
nextValidToken();
- if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
{
// we're done reading the array, so return it
return a;
}
- else if ( token.type == JSON_TOKEN::COMMA )
+ else if ( token.type == JSONTokenType.COMMA )
{
// move past the comma and read another value
nextToken();
@@ -190,7 +190,7 @@ package com.adobe.serialization.json
checkValidToken();
// Reached ",]" as the end of the array, so return it
- if ( token.type == JSON_TOKEN::RIGHT_BRACKET )
+ if ( token.type == JSONTokenType.RIGHT_BRACKET )
{
return a;
}
@@ -222,20 +222,20 @@ package com.adobe.serialization.json
nextValidToken();
// check to see if we have an empty object
- if ( token.type == JSON_TOKEN::RIGHT_BRACE )
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
{
// we're done reading the object, so return it
return o;
}
// in non-strict mode an empty object is also a comma
// followed by a right bracket
- else if ( !strict && token.type == JSON_TOKEN::COMMA )
+ else if ( !strict && token.type == JSONTokenType.COMMA )
{
// move past the comma
nextValidToken();
// check to see if we're reached the end of the object
- if ( token.type == JSON_TOKEN::RIGHT_BRACE )
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
{
return o;
}
@@ -249,7 +249,7 @@ package com.adobe.serialization.json
// loop because we could have any amount of members
while ( true )
{
- if ( token.type == JSON_TOKEN::STRING )
+ if ( token.type == JSONTokenType.STRING )
{
// the string value we read is the key for the object
key = String( token.value );
@@ -258,7 +258,7 @@ package com.adobe.serialization.json
nextValidToken();
// after the string there should be a :
- if ( token.type == JSON_TOKEN::COLON )
+ if ( token.type == JSONTokenType.COLON )
{
// move past the : and read/assign a value for the key
nextToken();
@@ -268,12 +268,12 @@ package com.adobe.serialization.json
nextValidToken();
// after the value there's either a } or a ,
- if ( token.type == JSON_TOKEN::RIGHT_BRACE )
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
{
// we're done reading the object, so return it
return o;
}
- else if ( token.type == JSON_TOKEN::COMMA )
+ else if ( token.type == JSONTokenType.COMMA )
{
// skip past the comma and read another member
nextToken();
@@ -285,7 +285,7 @@ package com.adobe.serialization.json
checkValidToken();
// Reached ",}" as the end of the object, so return it
- if ( token.type == JSON_TOKEN::RIGHT_BRACE )
+ if ( token.type == JSONTokenType.RIGHT_BRACE )
{
return o;
}
@@ -318,20 +318,20 @@ package com.adobe.serialization.json
switch ( token.type )
{
- case JSON_TOKEN::LEFT_BRACE:
+ case JSONTokenType.LEFT_BRACE:
return parseObject();
- case JSON_TOKEN::LEFT_BRACKET:
+ case JSONTokenType.LEFT_BRACKET:
return parseArray();
- case JSON_TOKEN::STRING:
- case JSON_TOKEN::NUMBER:
- case JSON_TOKEN::TRUE:
- case JSON_TOKEN::FALSE:
- case JSON_TOKEN::NULL:
+ case JSONTokenType.STRING:
+ case JSONTokenType.NUMBER:
+ case JSONTokenType.TRUE:
+ case JSONTokenType.FALSE:
+ case JSONTokenType.NULL:
return token.value;
- case JSON_TOKEN::NAN:
+ case JSONTokenType.NAN:
if ( !strict )
{
return token.value;
View
4 src/com/adobe/serialization/json/JSONToken.as
@@ -63,7 +63,7 @@ package com.adobe.serialization.json
* @playerversion Flash 9.0
* @tiptext
*/
- public function JSONToken( type:int = JSON_TOKEN::UNKNOWN, value:Object = null )
+ public function JSONToken( type:int = -1 /* JSONTokenType.UNKNOWN */, value:Object = null )
{
this.type = type;
this.value = value;
@@ -81,7 +81,7 @@ package com.adobe.serialization.json
* of a token at a time, we can always use the same instance to improve performance
* and reduce memory consumption during decoding.
*/
- internal static function create( type:int = JSON_TOKEN::UNKNOWN, value:Object = null ):JSONToken
+ internal static function create( type:int = -1 /* JSONTokenType.UNKNOWN */, value:Object = null ):JSONToken
{
token.type = type;
token.value = value;
View
69 src/com/adobe/serialization/json/JSONTokenType.as
@@ -0,0 +1,69 @@
+/*
+ Copyright (c) 2008, Adobe Systems Incorporated
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ * Neither the name of Adobe Systems Incorporated nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.adobe.serialization.json
+{
+
+ /**
+ * Class containing constant values for the different types
+ * of tokens in a JSON encoded string.
+ */
+ public final class JSONTokenType
+ {
+ public static const UNKNOWN:int = -1;
+
+ public static const COMMA:int = 0;
+
+ public static const LEFT_BRACE:int = 1;
+
+ public static const RIGHT_BRACE:int = 2;
+
+ public static const LEFT_BRACKET:int = 3;
+
+ public static const RIGHT_BRACKET:int = 4;
+
+ public static const COLON:int = 6;
+
+ public static const TRUE:int = 7;
+
+ public static const FALSE:int = 8;
+
+ public static const NULL:int = 9;
+
+ public static const STRING:int = 10;
+
+ public static const NUMBER:int = 11;
+
+ public static const NAN:int = 12;
+
+ }
+}
View
24 src/com/adobe/serialization/json/JSONTokenizer.as
@@ -95,32 +95,32 @@ package com.adobe.serialization.json
switch ( ch )
{
case '{':
- token = JSONToken.create( JSON_TOKEN::LEFT_BRACE, ch );
+ token = JSONToken.create( JSONTokenType.LEFT_BRACE, ch );
nextChar();
break
case '}':
- token = JSONToken.create( JSON_TOKEN::RIGHT_BRACE, ch );
+ token = JSONToken.create( JSONTokenType.RIGHT_BRACE, ch );
nextChar();
break
case '[':
- token = JSONToken.create( JSON_TOKEN::LEFT_BRACKET, ch );
+ token = JSONToken.create( JSONTokenType.LEFT_BRACKET, ch );
nextChar();
break
case ']':
- token = JSONToken.create( JSON_TOKEN::RIGHT_BRACKET, ch );
+ token = JSONToken.create( JSONTokenType.RIGHT_BRACKET, ch );
nextChar();
break
case ',':
- token = JSONToken.create( JSON_TOKEN::COMMA, ch );
+ token = JSONToken.create( JSONTokenType.COMMA, ch );
nextChar();
break
case ':':
- token = JSONToken.create( JSON_TOKEN::COLON, ch );
+ token = JSONToken.create( JSONTokenType.COLON, ch );
nextChar();
break;
@@ -129,7 +129,7 @@ package com.adobe.serialization.json
if ( possibleTrue == "true" )
{
- token = JSONToken.create( JSON_TOKEN::TRUE, true );
+ token = JSONToken.create( JSONTokenType.TRUE, true );
nextChar();
}
else
@@ -144,7 +144,7 @@ package com.adobe.serialization.json
if ( possibleFalse == "false" )
{
- token = JSONToken.create( JSON_TOKEN::FALSE, false );
+ token = JSONToken.create( JSONTokenType.FALSE, false );
nextChar();
}
else
@@ -159,7 +159,7 @@ package com.adobe.serialization.json
if ( possibleNull == "null" )
{
- token = JSONToken.create( JSON_TOKEN::NULL, null );
+ token = JSONToken.create( JSONTokenType.NULL, null );
nextChar();
}
else
@@ -174,7 +174,7 @@ package com.adobe.serialization.json
if ( possibleNaN == "NaN" )
{
- token = JSONToken.create( JSON_TOKEN::NAN, NaN );
+ token = JSONToken.create( JSONTokenType.NAN, NaN );
nextChar();
}
else
@@ -264,7 +264,7 @@ package com.adobe.serialization.json
// Unescape the string
// the token for the string we'll try to read
var token:JSONToken = JSONToken.create(
- JSON_TOKEN::STRING,
+ JSONTokenType.STRING,
// Attach resulting string to the token to return it
unescapeString( jsonString.substr( loc, quoteIndex - loc ) ) );
@@ -523,7 +523,7 @@ package com.adobe.serialization.json
if ( isFinite( num ) && !isNaN( num ) )
{
// the token for the number that we've read
- return JSONToken.create( JSON_TOKEN::NUMBER, num );
+ return JSONToken.create( JSONTokenType.NUMBER, num );
}
else
{

1 comment on commit 24c6c16

@dwabyick

was this a performance optimization? seems like a good idea. I know that static accessors are supposed to be slow. trying to think of a better workaround.

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