Skip to content

Commit 032d7dc

Browse files
committed
xrd: add Xdr#xdrEncodeShallowByteBuffer(Buffer)
Motivation: If client code already has grizzly Buffer direct use of it will avoud extra allocations. Modification: introduce Xdr#xdrEncodeShallowByteBuffer(Buffer) Result: better performance when grizzy polled buffers are used. Acked-by: Lea Morschel Target: master
1 parent 506c949 commit 032d7dc

File tree

1 file changed

+16
-4
lines changed
  • oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr

1 file changed

+16
-4
lines changed

oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/Xdr.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2023 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -768,14 +768,26 @@ public void xdrEncodeByteBuffer(ByteBuffer buf) {
768768
* @param buf The buffer from which bytes are to be retrieved.
769769
*/
770770
public void xdrEncodeShallowByteBuffer(ByteBuffer buf) {
771+
var wrap = new ByteBufferWrapper(buf);
772+
wrap.allowBufferDispose(true);
773+
xdrEncodeShallowByteBuffer(wrap);
774+
}
775+
776+
/**
777+
* A version of {@link #xdrEncodeShallowByteBuffer(ByteBuffer)} which uses Grizzly {@code buffer}.
778+
* Note: any change to the {@code buf} will cause unpredicted behavior.
779+
*
780+
* @param buf The buffer from which bytes are to be retrieved.
781+
*/
782+
public void xdrEncodeShallowByteBuffer(Buffer buf) {
771783
int len = buf.remaining();
772784
int padding = (4 - (len & 3)) & 3;
773785
xdrEncodeInt(len);
774786
int ep = _buffer.position() + buf.remaining();
775-
var b = new ByteBufferWrapper(buf);
776-
b.allowBufferDispose(true);
787+
777788
var composite = BuffersBuffer.create(_memoryManager);
778-
composite.append(_buffer.slice(0, _buffer.position())).append(b);
789+
composite.allowBufferDispose(true);
790+
composite.append(_buffer.slice(0, _buffer.position())).append(buf);
779791
composite.position(ep);
780792
composite.limit(ep);
781793

0 commit comments

Comments
 (0)