Lovelyxredxpanda / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

Speedup 'escape', writeJSONString #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Invoke writeJSONString in your code 
2. Watch your app in JProfiler
3. Note that a lot of time is spent in 'escape' calling String.length

What version of the product are you using? On what operating system?
Version 1-1, any OS

Suggested fix:

In JSONValue.escape(String s, StringBuffer sb), replace

 for(int i=0;i<s.length();i++){

with

 final int len = s.length();
 for(int i=0;i<len;i++){

In addition, replace all instances of StringBuffer with StringBuilder

Original issue reported on code.google.com by kay.kase...@gmail.com on 28 Apr 2011 at 11:14

GoogleCodeExporter commented 9 years ago
Please do not change all instances of StringBuffer with StringBuilder as you 
will lose JDK1.4 compatibility!

Original comment by ottu...@gmail.com on 11 May 2011 at 9:01

GoogleCodeExporter commented 9 years ago
May consider improving performance of invoking s.length(), but may not change 
StringBuffer to StringBuilder.

Original comment by fangyid...@gmail.com on 12 May 2011 at 9:00

GoogleCodeExporter commented 9 years ago
Excellent, thanks!

Original comment by kay.kase...@gmail.com on 13 May 2011 at 2:19

GoogleCodeExporter commented 9 years ago
Hi,

   I added your suggested fix in my github tree you can find in [1].

Thanks
Bye
Piero
[1]https://github.com/ottuzzi/JSON-SIMPLE

Original comment by ottu...@gmail.com on 24 Aug 2011 at 1:44

GoogleCodeExporter commented 9 years ago
Implemented the length-caching suggestion in r213, but will defer on the 
StringBuilder replacement for backward compatibility reasons.

Original comment by jon.cham...@gmail.com on 10 Aug 2013 at 3:35