Class PooledSlice

java.lang.Object
dev.relism.flash.bytes.PooledSlice
All Implemented Interfaces:
ArrayBackedByteView, dev.relism.fpr.core.ByteView

public final class PooledSlice extends Object implements ArrayBackedByteView
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

A PooledSlice 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 over array[offset, offset + length). Zero allocation.
    • array

      public byte[] array()
      Description copied from interface: ArrayBackedByteView
      The backing array. Bytes [offset(), offset() + length()) belong to this view.
      Specified by:
      array in interface ArrayBackedByteView
    • offset

      public int offset()
      Description copied from interface: ArrayBackedByteView
      Offset of this view's first byte within ArrayBackedByteView.array().
      Specified by:
      offset in interface ArrayBackedByteView
    • length

      public int length()
      Specified by:
      length in interface dev.relism.fpr.core.ByteView
    • byteAt

      public byte byteAt(int index)
      Specified by:
      byteAt in interface dev.relism.fpr.core.ByteView