From 950c522cefeb3cb35477e985ae5fdbc81227c18e Mon Sep 17 00:00:00 2001
From: Aleksey Demakov <ademakov@gmail.com>
Date: Mon, 23 Jan 2012 16:30:06 +0400
Subject: [PATCH] Use assert in space_n() and key_def_n() functions. Clarify
 comment in index_count() function.

---
 mod/box/box.h | 8 ++------
 mod/box/box.m | 8 ++++----
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/mod/box/box.h b/mod/box/box.h
index a167590470..fcb031a079 100644
--- a/mod/box/box.h
+++ b/mod/box/box.h
@@ -155,9 +155,7 @@ extern iproto_callback rw_callback;
 static inline int
 space_n(struct space *sp)
 {
-	if (sp < space || sp >= (space + BOX_SPACE_MAX)) {
-		panic("Invalid space pointer");
-	}
+	assert(sp >= space && sp < (space + BOX_SPACE_MAX));
 	return sp - space;
 }
 
@@ -167,9 +165,7 @@ space_n(struct space *sp)
 static inline int
 key_def_n(struct space *sp, struct key_def *kp)
 {
-	if (kp < sp->key_defs || kp >= (sp->key_defs + sp->key_count)) {
-		panic("Invalid key_def pointer");
-	}
+	assert(kp >= sp->key_defs && kp < (sp->key_defs + sp->key_count));
 	return kp - sp->key_defs;
 }
 
diff --git a/mod/box/box.m b/mod/box/box.m
index cffe640004..ad926279e0 100644
--- a/mod/box/box.m
+++ b/mod/box/box.m
@@ -94,10 +94,10 @@ index_count(struct space *sp)
 {
 	if (!secondary_indexes_enabled) {
 		/* If the secondary indexes are not enabled yet
-		   then we can use only the primary key if any.
-		   So return 1 of there is at least one key which
-		   must be primary and return 0 otherwise. */
-		return sp->key_count >= 1;
+		   then we can use only the primary index. So
+		   return 1 if there is at least one index (which
+		   must be primary) and return 0 otherwise. */
+		return sp->key_count > 0;
 	} else {
 		/* Return the actual number of indexes. */
 		return sp->key_count;
-- 
GitLab