mirror of https://github.com/apache/lucene.git
SOLR-276: improve JSON writer speed
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@551170 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
951dab2048
commit
79b3ef65c3
|
@ -78,6 +78,7 @@ New Features
|
|||
Changes in runtime behavior
|
||||
|
||||
Optimizations
|
||||
1. SOLR-276: improve JSON writer speed. (yonik)
|
||||
|
||||
Bug Fixes
|
||||
1. Make TextField respect sortMissingFirst and sortMissingLast fields.
|
||||
|
|
|
@ -458,7 +458,6 @@ class JSONWriter extends TextResponseWriter {
|
|||
|
||||
|
||||
public void writeStr(String name, String val, boolean needsEscaping) throws IOException {
|
||||
writer.write('"');
|
||||
// it might be more efficient to use a stringbuilder or write substrings
|
||||
// if writing chars to the stream is slow.
|
||||
if (needsEscaping) {
|
||||
|
@ -471,33 +470,40 @@ class JSONWriter extends TextResponseWriter {
|
|||
characters (U+0000 through U+001F).
|
||||
*/
|
||||
|
||||
StringBuilder sb = new StringBuilder(val.length()+8);
|
||||
sb.append('"');
|
||||
|
||||
for (int i=0; i<val.length(); i++) {
|
||||
char ch = val.charAt(i);
|
||||
switch(ch) {
|
||||
case '"':
|
||||
case '\\':
|
||||
writer.write('\\');
|
||||
writer.write(ch);
|
||||
sb.append('\\');
|
||||
sb.append(ch);
|
||||
break;
|
||||
case '\r': writer.write("\\r"); break;
|
||||
case '\n': writer.write("\\n"); break;
|
||||
case '\t': writer.write("\\t"); break;
|
||||
case '\b': writer.write("\\b"); break;
|
||||
case '\f': writer.write("\\f"); break;
|
||||
case '\r': sb.append('\\').append('r'); break;
|
||||
case '\n': sb.append('\\').append('n'); break;
|
||||
case '\t': sb.append('\\').append('t'); break;
|
||||
case '\b': sb.append('\\').append('b'); break;
|
||||
case '\f': sb.append('\\').append('f'); break;
|
||||
// case '/':
|
||||
default: {
|
||||
if (ch <= 0x1F) {
|
||||
unicodeEscape(writer,ch);
|
||||
unicodeEscape(sb,ch);
|
||||
} else {
|
||||
writer.write(ch);
|
||||
sb.append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.append('"');
|
||||
writer.append(sb);
|
||||
} else {
|
||||
writer.write('"');
|
||||
writer.write(val);
|
||||
writer.write('"');
|
||||
}
|
||||
writer.write('"');
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue