diff options
author | TGIshib <justzeddicus@gmail.com> | 2016-08-26 19:41:32 +0300 |
---|---|---|
committer | TGIshib <justzeddicus@gmail.com> | 2016-08-26 19:41:32 +0300 |
commit | 7c69c5dc3d635e29e3442339caa8eb06b8b9775c (patch) | |
tree | f29985abd8b044f198629504161fa37000f8cd37 /java | |
parent | 9f16090f901c30f872422f60db21a0370dde8bbf (diff) | |
download | flatbuffers-7c69c5dc3d635e29e3442339caa8eb06b8b9775c.tar.gz flatbuffers-7c69c5dc3d635e29e3442339caa8eb06b8b9775c.tar.bz2 flatbuffers-7c69c5dc3d635e29e3442339caa8eb06b8b9775c.zip |
Fix lookupByKey, improve compareStrings
Diffstat (limited to 'java')
-rw-r--r-- | java/com/google/flatbuffers/Table.java | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/java/com/google/flatbuffers/Table.java b/java/com/google/flatbuffers/Table.java index 7bf07113..c9c65456 100644 --- a/java/com/google/flatbuffers/Table.java +++ b/java/com/google/flatbuffers/Table.java @@ -235,35 +235,33 @@ public class Table { int startPos_1 = offset_1 + SIZEOF_INT; int startPos_2 = offset_2 + SIZEOF_INT; int len = Math.min(len_1, len_2); + byte[] bbArray = bb.array(); for(int i = 0; i < len; i++) { - if (bb.array()[i + startPos_1] != bb.array()[i + startPos_2]) - return bb.array()[i + startPos_1] - bb.array()[i + startPos_2]; + if (bbArray[i + startPos_1] != bbArray[i + startPos_2]) + return bbArray[i + startPos_1] - bbArray[i + startPos_2]; } - if (len_1 < len_2) return -1; - if (len_1 > len_2) return 1; - return 0; + return len_1 - len_2; } /** * Compare string from the buffer with the 'String' object. * * @param offset_1 An 'int' index of the first string into the bb. - * @param key Second string. + * @param key Second string as a byte array. * @param bb A {@code ByteBuffer} to get the first string. */ - protected static int compareStrings(int offset_1, String key, ByteBuffer bb) { + protected static int compareStrings(int offset_1, byte[] key, ByteBuffer bb) { offset_1 += bb.getInt(offset_1); int len_1 = bb.getInt(offset_1); - int len_2 = key.length(); + int len_2 = key.length; int startPos_1 = offset_1 + Constants.SIZEOF_INT; int len = Math.min(len_1, len_2); + byte[] bbArray = bb.array(); for (int i = 0; i < len; i++) { - if (bb.array()[i + startPos_1] != key.charAt(i)) - return bb.array()[i + startPos_1] - key.charAt(i); + if (bbArray[i + startPos_1] != key[i]) + return bbArray[i + startPos_1] - key[i]; } - if (len_1 < len_2) return -1; - if (len_1 > len_2) return 1; - return 0; + return len_1 - len_2; } } |