Directly init refCnt to 1 (#8274)

Motivation:

We should just directly init the refCnt to 1 and not use the AtomicIntegerFieldUpdater.

Modifications:

Just assing directly to 1.

Result:

Cleaner code and possible a bit faster as the JVM / JIT may be able to optimize the first store easily.
This commit is contained in:
Norman Maurer 2018-09-07 19:04:19 +02:00 committed by GitHub
parent e542a2cf26
commit c14efd952d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,7 +31,7 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
private static final AtomicIntegerFieldUpdater<AbstractReferenceCountedByteBuf> refCntUpdater =
AtomicIntegerFieldUpdater.newUpdater(AbstractReferenceCountedByteBuf.class, "refCnt");
private volatile int refCnt;
private volatile int refCnt = 1;
static {
long refCntFieldOffset = -1;
@ -49,7 +49,6 @@ public abstract class AbstractReferenceCountedByteBuf extends AbstractByteBuf {
protected AbstractReferenceCountedByteBuf(int maxCapacity) {
super(maxCapacity);
refCntUpdater.set(this, 1);
}
@Override