diff --git a/client/src/com/aerospike/client/BatchDelete.java b/client/src/com/aerospike/client/BatchDelete.java index 931babd94..2088d3a73 100644 --- a/client/src/com/aerospike/client/BatchDelete.java +++ b/client/src/com/aerospike/client/BatchDelete.java @@ -89,25 +89,31 @@ public boolean equals(BatchRecord obj, ConfigurationProvider configProvider) { public int size(Policy parentPolicy, ConfigurationProvider configProvider) { int size = 2; // gen(2) = 2 - if (policy != null) { - if (policy.filterExp != null) { - size += policy.filterExp.size(); - } + // Cache frequently accessed values to minimize field dereferences. + BatchDeletePolicy p = this.policy; + boolean parentSendKey = parentPolicy.sendKey; - boolean sendkey; - sendkey = policy.sendKey; - if (configProvider != null) { - Configuration config = configProvider.fetchConfiguration(); - if (config != null && config.hasDBDCsendKey()) { - sendkey = config.dynamicConfiguration.dynamicBatchDeleteConfig.sendKey.value; - } + if (p == null) { + if (parentSendKey) { + size += key.userKey.estimateSize() + Command.FIELD_HEADER_SIZE + 1; } + return size; + } - if (sendkey || parentPolicy.sendKey) { - size += key.userKey.estimateSize() + Command.FIELD_HEADER_SIZE + 1; + if (p.filterExp != null) { + size += p.filterExp.size(); + } + + boolean sendKey = p.sendKey; + + if (configProvider != null) { + Configuration config = configProvider.fetchConfiguration(); + if (config != null && config.hasDBDCsendKey()) { + sendKey = config.dynamicConfiguration.dynamicBatchDeleteConfig.sendKey.value; } } - else if (parentPolicy.sendKey) { + + if (sendKey || parentSendKey) { size += key.userKey.estimateSize() + Command.FIELD_HEADER_SIZE + 1; } return size;