Package dev.relism.flash.bytes
Class PooledSlice
java.lang.Object
dev.relism.flash.bytes.PooledSlice
- All Implemented Interfaces:
ArrayBackedByteView,dev.relism.fpr.core.ByteView
per-call
new ByteView() { ... } anonymous-class allocation that used to live in
Http1HeaderMap.view, QueryParams.view, and PathParams.view: instead of
allocating a fresh view object (plus its capturing instance) on every call, a small
SlicePool of these hands out an existing instance, repositioned in place.
Lifetime contract
APooledSlice handed out by SlicePool.acquire(byte[], int, int) is valid only until the pool
wraps around and reuses the same slot — see SlicePool's own Javadoc for the exact
"valid until the Nth subsequent acquire, or end of request" rule the owning class (e.g.
Http1HeaderMap) documents precisely for its own view() method. Never retain a
PooledSlice past that window, for the same reason the old anonymous view could not be
retained past the handler: the bytes (and, here, additionally the slice object itself) are
about to be repositioned out from under a stale reference.-
Constructor Details
-
PooledSlice
public PooledSlice()
-
-
Method Details
-
reset
public void reset(byte[] array, int offset, int length) Repositions this slice overarray[offset, offset + length). Zero allocation. -
array
public byte[] array()Description copied from interface:ArrayBackedByteViewThe backing array. Bytes[offset(), offset() + length())belong to this view.- Specified by:
arrayin interfaceArrayBackedByteView
-
offset
public int offset()Description copied from interface:ArrayBackedByteViewOffset of this view's first byte withinArrayBackedByteView.array().- Specified by:
offsetin interfaceArrayBackedByteView
-
length
public int length()- Specified by:
lengthin interfacedev.relism.fpr.core.ByteView
-
byteAt
public byte byteAt(int index) - Specified by:
byteAtin interfacedev.relism.fpr.core.ByteView
-