コード例 #1
0
 public String intern(CharSequence cs) {
   int h = Maths.hash(cs) & mask;
   String s = interner[h];
   if (StringUtils.isEqual(s, cs)) return s;
   String s2 = cs.toString();
   return interner[h] = s2;
 }
コード例 #2
0
  @NotNull
  @Override
  public BytesStore<Bytes<Underlying>, Underlying> copy() {
    if (bytesStore.underlyingObject() instanceof ByteBuffer) {
      ByteBuffer bb = ByteBuffer.allocateDirect(Maths.toInt32(readRemaining()));
      ByteBuffer bbu = (ByteBuffer) bytesStore.underlyingObject();
      ByteBuffer slice = bbu.slice();
      slice.position((int) readPosition());
      slice.limit((int) readLimit());
      bb.put(slice);
      bb.clear();
      return (BytesStore) BytesStore.wrap(bb);

    } else {
      return (BytesStore) NativeBytes.copyOf(this);
    }
  }
コード例 #3
0
  @NotNull
  @Override
  public BytesStore<NativeBytesStore<Underlying>, Underlying> copy() throws IllegalStateException {
    if (underlyingObject == null) {
      NativeBytesStore<Void> copy = of(realCapacity(), false, true);
      OS.memory().copyMemory(address, copy.address, capacity());
      return (BytesStore) copy;

    } else if (underlyingObject instanceof ByteBuffer) {
      ByteBuffer bb = ByteBuffer.allocateDirect(Maths.toInt32(capacity()));
      bb.put((ByteBuffer) underlyingObject);
      bb.clear();
      return (BytesStore) wrap(bb);

    } else {
      throw new UnsupportedOperationException();
    }
  }
コード例 #4
0
 public StringInterner(int capacity) {
   int n = Maths.nextPower2(capacity, 128);
   interner = new String[n];
   mask = n - 1;
 }