Skip to content

Commit

Permalink
fix(java): fix duplicate entry write at max chunk size bound (#2040)
Browse files Browse the repository at this point in the history
## What does this PR do?

 fix duplicate entry write at max chunk size bound
## Related issues

#2025
#2027 

## Does this PR introduce any user-facing change?

<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fury/issues/new/choose) describing the
need to do so and update the document if necessary.
-->

- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?

## Benchmark

<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
  • Loading branch information
chaokunyang authored Feb 6, 2025
1 parent f2d38ab commit b288a23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,6 @@ protected Expression writeChunk(
writeKey,
writeValue,
new Assign(chunkSize, add(chunkSize, ofInt(1))),
new If(eq(chunkSize, ofInt(MAX_CHUNK_SIZE)), new Break()),
new If(
inlineInvoke(iterator, "hasNext", PRIMITIVE_BOOLEAN_TYPE),
new ListExpression(
Expand All @@ -1348,7 +1347,8 @@ protected Expression writeChunk(
key,
tryInlineCast(inlineInvoke(entry, "getKey", OBJECT_TYPE), keyType)),
new Assign(value, invokeInline(entry, "getValue", valueType))),
list(new Assign(entry, new Literal(null, MAP_ENTRY_TYPE)), new Break())));
list(new Assign(entry, new Literal(null, MAP_ENTRY_TYPE)), new Break())),
new If(eq(chunkSize, ofInt(MAX_CHUNK_SIZE)), new Break()));
});
expressions.add(writeLoop, new Invoke(buffer, "putByte", chunkSizeOffset, chunkSize));
if (!inline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ private Entry writeJavaChunk(
valueSerializer.write(buffer, value);
}
// noinspection Duplicates
if (++chunkSize == MAX_CHUNK_SIZE) {
break;
}
++chunkSize;
if (iterator.hasNext()) {
entry = iterator.next();
key = entry.getKey();
Expand All @@ -326,6 +324,9 @@ private Entry writeJavaChunk(
entry = null;
break;
}
if (chunkSize == MAX_CHUNK_SIZE) {
break;
}
}
buffer.putByte(chunkSizeOffset, (byte) chunkSize);
return entry;
Expand Down Expand Up @@ -433,10 +434,8 @@ private Entry writeJavaChunkGeneric(
fury.incDepth(-1);
}
generics.popGenericType();
++chunkSize;
// noinspection Duplicates
if (++chunkSize == MAX_CHUNK_SIZE) {
break;
}
if (iterator.hasNext()) {
entry = iterator.next();
key = entry.getKey();
Expand All @@ -445,6 +444,9 @@ private Entry writeJavaChunkGeneric(
entry = null;
break;
}
if (chunkSize == MAX_CHUNK_SIZE) {
break;
}
}
buffer.putByte(chunkSizeOffset, (byte) chunkSize);
return entry;
Expand Down

0 comments on commit b288a23

Please sign in to comment.