Skip to content

Commit 2026a85

Browse files
committed
Revert ASCII-specific optimizations 852 => 1386 ns/op
1 parent 877c05b commit 2026a85

File tree

1 file changed

+0
-47
lines changed

1 file changed

+0
-47
lines changed

src/main/java/com/arangodb/velocypack/VPackBuilder.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -623,53 +623,6 @@ private void appendSQLTimestamp(final Timestamp value) {
623623
}
624624

625625
private void appendString(final String value) throws VPackBuilderException {
626-
int tagPos = size;
627-
int strLen = value.length();
628-
629-
// Guess whether the end result will be short or long. Assume ASCII for now.
630-
int tagSizeLen = strLen <= 126 ? 1 : 9;
631-
632-
// Fast path. Assume ASCII.
633-
ensureCapacity(size + tagSizeLen + strLen);
634-
635-
// Reserve space for the tag + length.
636-
size += tagSizeLen;
637-
638-
// Fast+tight loop for ASCII-only, no-escaping-needed output
639-
// Implementation lifted from jackson's UTF8JsonGenerator.
640-
int[] escCodes = CharTypes.get7BitOutputEscapes();
641-
int offset = 0;
642-
while(offset < strLen) {
643-
int ch = value.charAt(offset);
644-
if (ch > 0x7F || escCodes[ch] != 0) {
645-
break; // Not ASCII.
646-
}
647-
buffer[size++] = (byte) ch;
648-
++offset;
649-
}
650-
651-
if (offset < strLen) {
652-
// Not ASCII. Rewind and do the slow path.
653-
size = tagPos;
654-
appendUtf8String(value);
655-
return;
656-
}
657-
658-
// ASCII. strLen == bytes len.
659-
// Rewind size temporarily to write the header before the string data.
660-
size = tagPos;
661-
if (strLen <= 126) {
662-
// short string
663-
add((byte) (0x40 + strLen));
664-
} else {
665-
// long string
666-
add((byte) 0xbf);
667-
appendLength(strLen);
668-
}
669-
size += strLen;
670-
}
671-
672-
private void appendUtf8String(String value) {
673626
final byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
674627
final int length = bytes.length;
675628
if (length <= 126) {

0 commit comments

Comments
 (0)