Skip to content

Commit

Permalink
Avoid unnecessary allocations of PositionImpl (apache#5082)
Browse files Browse the repository at this point in the history
### Motivation

The PositionImpl class is used as immutable so there's no need to make defensive copies of it
  • Loading branch information
merlimat authored and sijie committed Aug 31, 2019
1 parent 26fe6b0 commit 5b266b4
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class ManagedCursorImpl implements ManagedCursor {
private RateLimiter markDeleteLimiter;

private boolean alwaysInactive = false;

/** used temporary variables to {@link #getNumIndividualDeletedEntriesToSkip(long)} **/
private static final FastThreadLocal<Long> tempTotalEntriesToSkip = new FastThreadLocal<>();
private static final FastThreadLocal<Long> tempDeletedMessages = new FastThreadLocal<>();
Expand All @@ -167,7 +167,7 @@ class MarkDeleteEntry {

public MarkDeleteEntry(PositionImpl newPosition, Map<String, Long> properties,
MarkDeleteCallback callback, Object ctx) {
this.newPosition = PositionImpl.get(newPosition);
this.newPosition = newPosition;
this.properties = properties;
this.callback = callback;
this.ctx = ctx;
Expand Down Expand Up @@ -394,7 +394,7 @@ private void recoveredCursor(PositionImpl position, Map<String, Long> properties
if (position.compareTo(ledger.getLastPosition()) > 0) {
log.warn("[{}] [{}] Current position {} is ahead of last position {}", ledger.getName(), name, position,
ledger.getLastPosition());
position = PositionImpl.get(ledger.getLastPosition());
position = ledger.getLastPosition();
}
log.info("[{}] Cursor {} recovered to position {}", ledger.getName(), name, position);

Expand Down Expand Up @@ -474,7 +474,7 @@ public void asyncReadEntries(final int numberOfEntriesToRead, final ReadEntriesC
}

PENDING_READ_OPS_UPDATER.incrementAndGet(this);
OpReadEntry op = OpReadEntry.create(this, PositionImpl.get(readPosition), numberOfEntriesToRead, callback, ctx);
OpReadEntry op = OpReadEntry.create(this, readPosition, numberOfEntriesToRead, callback, ctx);
ledger.asyncReadEntries(op);
}

Expand Down Expand Up @@ -595,7 +595,7 @@ public void asyncReadEntriesOrWait(int numberOfEntriesToRead, ReadEntriesCallbac
}
asyncReadEntries(numberOfEntriesToRead, callback, ctx);
} else {
OpReadEntry op = OpReadEntry.create(this, PositionImpl.get(readPosition), numberOfEntriesToRead, callback,
OpReadEntry op = OpReadEntry.create(this, readPosition, numberOfEntriesToRead, callback,
ctx);

if (!WAITING_READ_OP_UPDATER.compareAndSet(this, null, op)) {
Expand Down Expand Up @@ -1397,7 +1397,7 @@ PositionImpl setAcknowledgedPosition(PositionImpl newMarkDeletePosition) {
}
break;
}

if (log.isDebugEnabled()) {
log.debug("[{}] Moved ack position from: {} to: {} -- skipped: {}", ledger.getName(),
oldMarkDeletePosition, newMarkDeletePosition, skippedEntries);
Expand All @@ -1406,7 +1406,7 @@ PositionImpl setAcknowledgedPosition(PositionImpl newMarkDeletePosition) {
}

// markDelete-position and clear out deletedMsgSet
markDeletePosition = PositionImpl.get(newMarkDeletePosition);
markDeletePosition = newMarkDeletePosition;
individualDeletedMessages.removeAtMost(markDeletePosition.getLedgerId(), markDeletePosition.getEntryId());

if (readPosition.compareTo(newMarkDeletePosition) <= 0) {
Expand Down Expand Up @@ -1846,12 +1846,12 @@ public boolean isDurable() {

@Override
public Position getReadPosition() {
return PositionImpl.get(readPosition);
return readPosition;
}

@Override
public Position getMarkDeletedPosition() {
return PositionImpl.get(markDeletePosition);
return markDeletePosition;
}

@Override
Expand Down

0 comments on commit 5b266b4

Please sign in to comment.