Repository: netty/netty
File: buffer/src/main/java/io/netty/buffer/UnpooledUnsafeDirectByteBuf.java (Java)

Code before:
            return;
        }
        UnsafeByteBufUtil.setInt(addr(index), value);
    }

    @Override
    protected void _setIntLE(int index, int value) {
        if (!PlatformDependent.isUnaligned() &&
                !PlatformDependent.isUnalignedAvailable() && PlatformDependent.hasVarHandle()) {
            VarHandleByteBufferAccess.setIntLE(buffer, index, value);
            return;
        }
        UnsafeByteBufUtil.setIntLE(addr(index), value);
    }

    @Override
    public ByteBuf setLong(int index, long value) {
        checkIndex(index, 8);
        _setLong(index, value);
        return this;
    }

    @Override
    protected void _setLong(int index, long value) {
        if (!PlatformDependent.isUnaligned() &&
                !PlatformDependent.isUnalignedAvailable() && PlatformDependent.hasVarHandle()) {
            VarHandleByteBufferAccess.setLongBE(buffer, index, value);
            return;
        }
        UnsafeByteBufUtil.setLong(addr(index), value);
    }

    @Override
    protected void _setLongLE(int index, long value) {
        if (!PlatformDependent.isUnaligned() &&
                !PlatformDependent.isUnalignedAvailable() && PlatformDependent.hasVarHandle()) {
            VarHandleByteBufferAccess.setLongLE(buffer, index, value);
            return;
        }
        UnsafeByteBufUtil.setLongLE(addr(index), value);
    }

    @Override
    public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
        UnsafeByteBufUtil.setBytes(this, addr(index), index, src, srcIndex, length);
        return this;
    }

    @Override
    public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
        UnsafeByteBufUtil.setBytes(this, addr(index), index, src, srcIndex, length);

Review comment (refactor):
Why not combine these once in a static boolean to simplify ?

```
private static final USE_VAR_HANDLE = !PlatformDependent.isUnaligned() &&
                !PlatformDependent.isUnalignedAvailable() && PlatformDependent.hasVarHandle();
...
...
if (USE_VAR_HANDLE) {
    ....
}
```

Code after:
        if (USE_VAR_HANDLE) {
            VarHandleByteBufferAccess.setIntLE(buffer, index, value);
            return;
        }
        UnsafeByteBufUtil.setIntLE(addr(index), value);
    }

    @Override
    public ByteBuf setLong(int index, long value) {
        checkIndex(index, 8);
        _setLong(index, value);
        return this;
    }

    @Override
    protected void _setLong(int index, long value) {
        if (USE_VAR_HANDLE) {
            VarHandleByteBufferAccess.setLongBE(buffer, index, value);
            return;
        }
        UnsafeByteBufUtil.setLong(addr(index), value);
    }

    @Override
    protected void _setLongLE(int index, long value) {
        if (USE_VAR_HANDLE) {
            VarHandleByteBufferAccess.setLongLE(buffer, index, value);
            return;
        }
        UnsafeByteBufUtil.setLongLE(addr(index), value);
    }

    @Override
    public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
        UnsafeByteBufUtil.setBytes(this, addr(index), index, src, srcIndex, length);
        return this;
    }

    @Override
    public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
        UnsafeByteBufUtil.setBytes(this, addr(index), index, src, srcIndex, length);
        return this;
    }

    @Override
    public ByteBuf setBytes(int index, ByteBuffer src) {
        UnsafeByteBufUtil.setBytes(this, addr(index), index, src);
        return this;
    }

    @Override