mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-24 02:18:47 +08:00
bugfix for substring
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.TimeZone;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.util.ASMUtils;
|
||||
import com.alibaba.fastjson.util.Base64;
|
||||
|
||||
//这个类,为了性能优化做了很多特别处理,一切都是为了性能!!!
|
||||
@@ -167,15 +168,23 @@ public final class JSONScanner extends JSONLexerBase {
|
||||
*/
|
||||
public final String stringVal() {
|
||||
if (!hasSpecial) {
|
||||
// return new String(buf, np + 1, sp);
|
||||
return text.substring(np + 1, np + 1 + sp);
|
||||
// return text.substring(np + 1, np + 1 + sp);
|
||||
return this.subString(np + 1, sp);
|
||||
} else {
|
||||
return new String(sbuf, 0, sp);
|
||||
}
|
||||
}
|
||||
|
||||
public final String subString(int offset, int count) {
|
||||
return text.substring(offset, offset + count);
|
||||
if (ASMUtils.isAndroid()) {
|
||||
char[] chars = new char[count];
|
||||
for (int i = offset; i < offset + count; ++i) {
|
||||
chars[i - offset] = text.charAt(i);
|
||||
}
|
||||
return new String(chars);
|
||||
} else {
|
||||
return text.substring(offset, offset + count);
|
||||
}
|
||||
}
|
||||
|
||||
public final String numberString() {
|
||||
@@ -186,8 +195,8 @@ public final class JSONScanner extends JSONLexerBase {
|
||||
sp--;
|
||||
}
|
||||
|
||||
return text.substring(np, np + sp);
|
||||
// return new String(buf, np, sp);
|
||||
// return text.substring(np, np + sp);
|
||||
return this.subString(np, sp);
|
||||
}
|
||||
|
||||
public final int ISO8601_LEN_0 = "0000-00-00".length();
|
||||
@@ -881,8 +890,8 @@ public final class JSONScanner extends JSONLexerBase {
|
||||
for (;;) {
|
||||
ch = charAt(index++);
|
||||
if (ch == '\"') {
|
||||
strVal = text.substring(start, index - 1);
|
||||
// strVal = new String(buf, start, index - start - 1);
|
||||
// strVal = text.substring(start, index - 1);
|
||||
strVal = this.subString(start, index - start - 1);
|
||||
list.add(strVal);
|
||||
ch = charAt(index++);
|
||||
break;
|
||||
|
||||
@@ -176,14 +176,14 @@ public class SymbolTable {
|
||||
}
|
||||
}
|
||||
if (entryIndex >= MAX_BUCKET_LENTH) {
|
||||
return buffer.substring(offset, offset + len);
|
||||
// return new String(buffer, offset, len);
|
||||
// return buffer.substring(offset, offset + len);
|
||||
return subString(buffer, offset, len);
|
||||
}
|
||||
}
|
||||
|
||||
if (size >= MAX_SIZE) {
|
||||
// return new String(buffer, offset, len);
|
||||
return buffer.substring(offset, offset + len);
|
||||
// return buffer.substring(offset, offset + len);
|
||||
return subString(buffer, offset, len);
|
||||
}
|
||||
|
||||
Entry entry = new Entry(buffer, offset, len, hash, buckets[bucket]);
|
||||
@@ -195,6 +195,14 @@ public class SymbolTable {
|
||||
size++;
|
||||
return entry.symbol;
|
||||
}
|
||||
|
||||
private static String subString(String src, int offset, int len) {
|
||||
char[] chars = new char[len];
|
||||
for (int i = offset; i < offset + len; ++i) {
|
||||
chars[i - offset] = src.charAt(i);
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
@@ -233,7 +241,8 @@ public class SymbolTable {
|
||||
}
|
||||
|
||||
public Entry(String text, int offset, int length, int hash, Entry next){
|
||||
symbol = text.substring(offset, offset + length).intern();
|
||||
// symbol = text.substring(offset, offset + length).intern();
|
||||
symbol = subString(text, offset, length).intern();
|
||||
characters = symbol.toCharArray();
|
||||
this.next = next;
|
||||
this.hashCode = hash;
|
||||
|
||||
Reference in New Issue
Block a user