From 584a8d9cfba26f686ec6b97982c703042a1c641f Mon Sep 17 00:00:00 2001
From: Andrey Saranchin <Andrey22102001@gmail.com>
Date: Fri, 23 Aug 2024 21:05:24 +0300
Subject: [PATCH] memtx: refactor `memtx_tx_unlink_top_on_space_delete`

The helper consists of `unlink_top_common` and
`unlink_top_on_space_delete_light` helpers. It would make sense if
`unlink_top_common` would be used in any other place, but it's used only
here actually. Let's inline this helpers - it will be easier to read
this code and it will allow to simply patch this function in future
commits.

NO_TEST=refactoring
NO_CHANGELOG=refactoring
NO_DOC=refactoring

(cherry picked from commit 7b2243828937413db9b1c3ffcf8abd8fd92daf02)
---
 src/box/memtx_tx.c | 50 +++-------------------------------------------
 1 file changed, 3 insertions(+), 47 deletions(-)

diff --git a/src/box/memtx_tx.c b/src/box/memtx_tx.c
index f9e32cbc11..1e776c584d 100644
--- a/src/box/memtx_tx.c
+++ b/src/box/memtx_tx.c
@@ -1195,15 +1195,9 @@ memtx_tx_story_link_top(struct memtx_story *new_top,
 	rlist_splice(&new_link->read_gaps, &old_link->read_gaps);
 }
 
-/**
- * Unlink a @a story from history chain in @a index (in both directions),
- * where old_top was at the top of chain (that means that index itself
- * stores a pointer to story->tuple).
- * This function makes also changes in the index, replacing old_top->tuple
- * with the correct tuple (the next in chain, maybe NULL).
- */
 static void
-memtx_tx_story_unlink_top_common(struct memtx_story *story, uint32_t idx)
+memtx_tx_story_unlink_top_on_space_delete(struct memtx_story *story,
+					  uint32_t idx)
 {
 	assert(story != NULL);
 	assert(idx < story->index_count);
@@ -1248,50 +1242,12 @@ memtx_tx_story_unlink_top_common(struct memtx_story *story, uint32_t idx)
 			memtx_tx_ref_to_primary(old_story);
 		memtx_tx_unref_from_primary(story);
 	}
-}
 
-/**
- * Unlink a @a story from history chain in @a index (in both directions),
- * where old_top was at the top of chain (that means that index itself
- * stores a pointer to story->tuple).
- * This is a light version of function, intended for the case when the
- * appropriate change in the index will be done later by caller.
- */
-static void
-memtx_tx_story_unlink_top_common_light(struct memtx_story *story, uint32_t idx)
-{
-	assert(story != NULL);
-	assert(idx < story->index_count);
-	struct memtx_story_link *link = &story->link[idx];
-	assert(link->newer_story == NULL);
-	struct memtx_story *old_story = link->older_story;
+	/* Now simply unlink the story. */
 	if (old_story != NULL)
 		memtx_tx_story_unlink(story, old_story, idx);
 }
 
-/**
- * See description of `memtx_tx_story_unlink_top_common_light`.
- * Since the space is being deleted, we need to simply unlink the story.
- */
-static void
-memtx_tx_story_unlink_top_on_space_delete_light(struct memtx_story *story,
-						uint32_t idx)
-{
-	memtx_tx_story_unlink_top_common_light(story, idx);
-}
-
-/**
- * See description of `memtx_tx_story_unlink_top_common`.
- * Since the space is being deleted, we need to simply unlink the story.
- */
-static void
-memtx_tx_story_unlink_top_on_space_delete(struct memtx_story *story,
-					  uint32_t idx)
-{
-	memtx_tx_story_unlink_top_common(story, idx);
-	memtx_tx_story_unlink_top_on_space_delete_light(story, idx);
-}
-
 /**
  * Unlink a @a story from history chain in @a index in both directions.
  * Handles case when the story is not on top of the history: simply remove from
-- 
GitLab