[Tarantool-patches] [PATCH 02/11] vclock: vclock_get - drop misleading masking

Cyrill Gorcunov gorcunov at gmail.com
Thu Nov 12 22:51:12 MSK 2020


We rely heavily that VCLOCK_MAX is 32 bits wide
and using "VCLOCK_MAX - 1" as a mask for safe
access to the replica id is simply misleading.

Instead use assert here because we might change
the number of supported replicas one day and they
do not have to be pow2 value.

And no need for this completely useless comment.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 src/lib/vclock/vclock.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/lib/vclock/vclock.h b/src/lib/vclock/vclock.h
index 5865f7443..fd4072c94 100644
--- a/src/lib/vclock/vclock.h
+++ b/src/lib/vclock/vclock.h
@@ -160,11 +160,7 @@ vclock_is_set(const struct vclock *vclock)
 static inline int64_t
 vclock_get(const struct vclock *vclock, uint32_t replica_id)
 {
-	/*
-	 * If replica_id does not fit in VCLOCK_MAX - 1 then
-	 * let result be undefined.
-	 */
-	replica_id &= VCLOCK_MAX - 1;
+	assert(replica_id < VCLOCK_MAX);
 	/* Evaluate a bitmask to avoid branching. */
 	int64_t mask = 0ULL - ((vclock->map >> replica_id) & 0x1);
 	return mask & vclock->lsn[replica_id];
-- 
2.26.2



More information about the Tarantool-patches mailing list