Skip to content

Instantly share code, notes, and snippets.

@sugmanue
Created November 15, 2024 23:19
Show Gist options
  • Save sugmanue/44124c3b12095e82ef82e6d303a3ae35 to your computer and use it in GitHub Desktop.
Save sugmanue/44124c3b12095e82ef82e6d303a3ae35 to your computer and use it in GitHub Desktop.
Tweaks to the ASCII loop for CBOR
✗ git diff
diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java
index a87cf82d..da92bffe 100644
--- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java
+++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java
@@ -2364,16 +2364,21 @@ public class CBORParser extends ParserMinimalBase
final int end = _inputPtr;
int i;
- while ((i = inputBuf[inPtr]) >= 0) {
+ while (inPtr < end) {
+ i = inputBuf[inPtr];
+ if (i < 0) {
+ break;
+ }
+ ++inPtr;
outBuf[outPtr++] = (char) i;
- if (++inPtr == end) {
- String str = _textBuffer.setCurrentAndReturn(outPtr);
- if (stringRefs != null) {
- stringRefs.stringRefs.add(str);
- _sharedString = str;
- }
- return str;
+ }
+ if (inPtr == end) {
+ String str = _textBuffer.setCurrentAndReturn(outPtr);
+ if (stringRefs != null) {
+ stringRefs.stringRefs.add(str);
+ _sharedString = str;
}
+ return str;
}
final int[] codes = UTF8_UNIT_CODES;
do {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment