Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH v1 1/1] Implement mp_stack_top for mp_stack class
@ 2019-04-02 15:49 Kirill Shcherbatov
  2019-04-03 12:12 ` Vladimir Davydov
  0 siblings, 1 reply; 8+ messages in thread
From: Kirill Shcherbatov @ 2019-04-02 15:49 UTC (permalink / raw)
  To: tarantool-patches, vdavydov.dev; +Cc: Kirill Shcherbatov

Introduced a new mp_stack_top method for mp_stack class to
return the pointer to a top frame of the stack.

This is required in scope of multikey indexes to keep a pointer
to a multikey frame and extract currently processed item index
of this frame later.

Needed for https://github.com/tarantool/tarantool/issues/1257
---
https://github.com/tarantool/msgpuck/tree/kshch/gh-1257-new-mpstacktop-method
https://github.com/tarantool/tarantool/issues/1257

 msgpuck.h | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/msgpuck.h b/msgpuck.h
index eab1339..c91d5d1 100644
--- a/msgpuck.h
+++ b/msgpuck.h
@@ -1278,6 +1278,14 @@ mp_stack_is_empty(struct mp_stack *stack);
 MP_PROTO bool
 mp_stack_is_full(struct mp_stack *stack);
 
+/**
+ * \brief Return the top mp_stack \a stack frame.
+ * \param stack - the pointer to a mp_stack to operate with.
+ * \pre mp_stack_is_empty(stack) == false
+ */
+MP_PROTO struct mp_frame *
+mp_stack_top(struct mp_stack *stack);
+
 /**
  * \brief Pop the top mp_stack \a stack frame.
  * \param stack - the pointer to a mp_stack to operate with.
@@ -2349,6 +2357,12 @@ mp_stack_is_full(struct mp_stack *stack)
 	return stack->used >= stack->size;
 }
 
+MP_IMPL struct mp_frame *
+mp_stack_top(struct mp_stack *stack)
+{
+	return &stack->frames[stack->used - 1];
+}
+
 MP_IMPL void
 mp_stack_pop(struct mp_stack *stack)
 {
@@ -2370,20 +2384,20 @@ MP_IMPL enum mp_type
 mp_stack_type(struct mp_stack *stack)
 {
 	assert(!mp_stack_is_empty(stack));
-	return stack->frames[stack->used - 1].type;
+	return mp_stack_top(stack)->type;
 }
 
 MP_IMPL int
 mp_stack_count(struct mp_stack *stack)
 {
-	return stack->frames[stack->used - 1].count;
+	return mp_stack_top(stack)->count;
 }
 
 MP_IMPL int
 mp_stack_advance(struct mp_stack *stack)
 {
 	assert(!mp_stack_is_empty(stack));
-	struct mp_frame *frame = &stack->frames[stack->used - 1];
+	struct mp_frame *frame = mp_stack_top(stack);
 	if (frame->curr < frame->count - 1)
 		return ++frame->curr;
 	return -1;
-- 
2.21.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-04-07 12:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-02 15:49 [PATCH v1 1/1] Implement mp_stack_top for mp_stack class Kirill Shcherbatov
2019-04-03 12:12 ` Vladimir Davydov
2019-04-03 15:16   ` [tarantool-patches] " Kirill Shcherbatov
2019-04-03 15:40     ` Vladimir Davydov
2019-04-03 17:49       ` Kirill Shcherbatov
2019-04-04 15:42         ` Vladimir Davydov
2019-04-05 17:17           ` Kirill Shcherbatov
2019-04-07 12:02             ` Vladimir Davydov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox