Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 226048 Details for
Bug 398973
Optimize string escaping in JsonValue class
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch with proposed changes
Improve-json-append-operations-in-JsonValue-class.patch (text/plain), 7.36 KB, created by
Ivan Furnadjiev
on 2013-01-24 09:42:55 EST
(
hide
)
Description:
Patch with proposed changes
Filename:
MIME Type:
Creator:
Ivan Furnadjiev
Created:
2013-01-24 09:42:55 EST
Size:
7.36 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/protocol/Operation.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/protocol/Operation.java >index 5444e3d..2547577 100644 >--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/protocol/Operation.java >+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/protocol/Operation.java >@@ -46,8 +46,7 @@ > > void appendProperties( Map<String, Object> properties ) { > if( properties != null && !properties.isEmpty() ) { >- Set<String> keySet = properties.keySet(); >- for( String key : keySet ) { >+ for( String key : properties.keySet() ) { > appendProperty( key, JsonUtil.createJsonValue( properties.get( key ) ) ); > } > } >diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonObject.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonObject.java >index 4ae4d4e..10274f8 100644 >--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonObject.java >+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonObject.java >@@ -49,6 +49,7 @@ > } > } > >+ @Override > public String toString() { > String tail = count == 0 ? "}" : "\n}"; > return buffer.toString() + tail; >@@ -56,7 +57,7 @@ > > private void doAppend( String key, String valueStr ) { > buffer.append( count == 0 ? "\n" : ",\n" ); >- buffer.append( quoteAndEscapeString( key ) ); >+ appendQuotedAndEscapedString( buffer, key ); > buffer.append( ": " ); > buffer.append( valueStr ); > count++; >diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonValue.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonValue.java >index 9c62fa6..0006306 100644 >--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonValue.java >+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/theme/JsonValue.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008, 2012 Innoopract Informationssysteme GmbH. >+ * Copyright (c) 2008, 2013 Innoopract Informationssysteme GmbH. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -60,42 +60,48 @@ > } > > static String quoteAndEscapeString( String string ) { >- StringBuilder resultBuffer = new StringBuilder(); >- resultBuffer.append( '"' ); >- resultBuffer.append( escapeString( string ) ); >- resultBuffer.append( '"' ); >- return resultBuffer.toString(); >+ StringBuilder buffer = new StringBuilder( string.length() + 2 ); >+ appendQuotedAndEscapedString( buffer, string ); >+ return buffer.toString(); > } > >- static String escapeString( String string ) { >- StringBuilder resultBuffer = new StringBuilder(); >- int length = string.length(); >+ static void appendQuotedAndEscapedString( StringBuilder buffer, String string ) { >+ buffer.append( '"' ); >+ appendEscapedString( buffer, string ); >+ buffer.append( '"' ); >+ } >+ >+ static void appendEscapedString( StringBuilder buffer, String string ) { >+ char[] chars = string.toCharArray(); >+ int length = chars.length; > for( int i = 0; i < length; i++ ) { >- char ch = string.charAt( i ); >+ char ch = chars[ i ]; > if( ch == '"' || ch == '\\' ) { >- resultBuffer.append( '\\' ); >- resultBuffer.append( ch ); >+ buffer.append( '\\' ); >+ buffer.append( ch ); > } else if( ch == '\n' ) { >- resultBuffer.append( "\\n" ); >+ buffer.append( '\\' ); >+ buffer.append( 'n' ); > } else if( ch == '\r' ) { >- resultBuffer.append( "\\r" ); >+ buffer.append( '\\' ); >+ buffer.append( 'r' ); > } else if( ch == '\t' ) { >- resultBuffer.append( "\\t" ); >+ buffer.append( '\\' ); >+ buffer.append( 't' ); > } else if( ch == '\u2028' ) { >- resultBuffer.append( "\\u2028" ); >+ buffer.append( "\\u2028" ); > } else if( ch == '\u2029' ) { >- resultBuffer.append( "\\u2029" ); >+ buffer.append( "\\u2029" ); > } else if( ch >= CONTROL_CHARACTERS_START && ch <= CONTROL_CHARACTERS_END ) { >- resultBuffer.append( "\\u00" ); >+ buffer.append( "\\u00" ); > if( ch <= 0x000f ) { >- resultBuffer.append( "0" ); >+ buffer.append( '0' ); > } >- resultBuffer.append( Integer.toHexString( ch ) ); >+ buffer.append( Integer.toHexString( ch ) ); > } else { >- resultBuffer.append( ch ); >+ buffer.append( ch ); > } > } >- return resultBuffer.toString(); > } > > private static class JsonPrimitive extends JsonValue { >@@ -106,6 +112,7 @@ > this.value = value; > } > >+ @Override > public String toString() { > return value; > } >diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/theme/JsonValue_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/theme/JsonValue_Test.java >index 075c9d5..5acd6d5 100644 >--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/theme/JsonValue_Test.java >+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/theme/JsonValue_Test.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2008, 2012 Innoopract Informationssysteme GmbH and others. >+ * Copyright (c) 2008, 2013 Innoopract Informationssysteme GmbH and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -82,28 +82,28 @@ > @Test > public void testEscapeStringWithQuotes() { > // escape a\b -> "a\\b" >- assertEquals( "a\\\\b", JsonValue.escapeString( "a\\b" ) ); >+ assertEquals( "a\\\\b", escapeString( "a\\b" ) ); > // escape a"b -> "a\"b" >- assertEquals( "a\\\"b", JsonValue.escapeString( "a\"b" ) ); >+ assertEquals( "a\\\"b", escapeString( "a\"b" ) ); > // escape a\"b\" -> "a\\\"b\\\"" >- assertEquals( "a\\\\\\\"b\\\\\\\"", JsonValue.escapeString( "a\\\"b\\\"" ) ); >+ assertEquals( "a\\\\\\\"b\\\\\\\"", escapeString( "a\\\"b\\\"" ) ); > } > > @Test > public void testEscapeStringWithNewLines() { >- assertEquals( "a\\n", JsonValue.escapeString( "a\n" ) ); >- assertEquals( "a\\r\\nb", JsonValue.escapeString( "a\r\nb" ) ); >+ assertEquals( "a\\n", escapeString( "a\n" ) ); >+ assertEquals( "a\\r\\nb", escapeString( "a\r\nb" ) ); > } > > @Test > public void testEscapeStringWithTabs() { >- assertEquals( "a\\tb", JsonValue.escapeString( "a\tb" ) ); >+ assertEquals( "a\\tb", escapeString( "a\tb" ) ); > } > > @Test > public void testEscapeStringWithSpecialCharacters() { > String expected = "\\u2028foo\\u2029"; >- assertEquals( expected, JsonValue.escapeString( "\u2028foo\u2029" ) ); >+ assertEquals( expected, escapeString( "\u2028foo\u2029" ) ); > } > > @Test >@@ -126,4 +126,10 @@ > assertEquals( "\"hel\\u000flo\"", JsonValue.valueOf( String.valueOf( data ) ).toString() ); > } > >+ private static String escapeString( String string ) { >+ StringBuilder result = new StringBuilder(); >+ JsonValue.appendEscapedString( result, string ); >+ return result.toString(); >+ } >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 398973
: 226048