Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org, vdavydov@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 1/4] xrow: rework coio_read_xrow to keep parsed input
Date: Mon, 6 Dec 2021 06:05:59 +0300	[thread overview]
Message-ID: <8112214c-cfef-c791-80cf-fe4402540570@tarantool.org> (raw)
In-Reply-To: <76b802ed3cfa45a87f2610a9e05b71bc14dfb36a.1638757827.git.sergepetrenko@tarantool.org>


Here's the corresponding change in libsmall:

Subject: [PATCH] ibuf: introduce xpos field

ibuf->xpos is the pointer to the not-yet-parsed input, so that
rpos <= xpos <= wpos. This is useful when the user processes input in
multiple stages, and needs the input data for a longer period of time than
just "until the data is read".
---
https://github.com/tarantool/small/tree/sp/ibuf-xpos

include/small/ibuf.h | 10 +++++++++-
  small/ibuf.c         |  4 +++-
  2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/include/small/ibuf.h b/include/small/ibuf.h
index 00d7781..a6646b5 100644
--- a/include/small/ibuf.h
+++ b/include/small/ibuf.h
@@ -61,6 +61,8 @@ struct ibuf
      char *buf;
      /** Start of input. */
      char *rpos;
+    /** End of parsed input. */
+    char *xpos;
      /** End of useful input */
      char *wpos;
      /** End of buffer. */
@@ -100,6 +102,12 @@ ibuf_capacity(struct ibuf *ibuf)
      return ibuf->end - ibuf->buf;
  }

+static inline size_t
+ibuf_unparsed(struct ibuf *ibuf)
+{
+    return ibuf->wpos - ibuf->xpos;
+}
+
  /**
   * Integer value of the position in the buffer - stable
   * in case of realloc.
@@ -115,7 +123,7 @@ ibuf_pos(struct ibuf *ibuf)
  static inline void
  ibuf_reset(struct ibuf *ibuf)
  {
-    ibuf->rpos = ibuf->wpos = ibuf->buf;
+    ibuf->rpos = ibuf->xpos = ibuf->wpos = ibuf->buf;
  }

  void *
diff --git a/small/ibuf.c b/small/ibuf.c
index fe3f441..85345f4 100644
--- a/small/ibuf.c
+++ b/small/ibuf.c
@@ -37,7 +37,7 @@ void
  ibuf_create(struct ibuf *ibuf, struct slab_cache *slabc, size_t 
start_capacity)
  {
      ibuf->slabc = slabc;
-    ibuf->buf = ibuf->rpos = ibuf->wpos = ibuf->end = NULL;
+    ibuf->buf = ibuf->rpos = ibuf->xpos = ibuf->wpos = ibuf->end = NULL;
      ibuf->start_capacity = start_capacity;
      /* Don't allocate the buffer yet. */
  }
@@ -99,7 +99,9 @@ ibuf_reserve_slow(struct ibuf *ibuf, size_t size)
          ibuf->buf = ptr;
          ibuf->end = ibuf->buf + slab_capacity(slab);
      }
+    size_t xsize = ibuf->xpos - ibuf->rpos;
      ibuf->rpos = ibuf->buf;
+    ibuf->xpos = ibuf->rpos + xsize;
      ibuf->wpos = ibuf->rpos + used;
      return ibuf->wpos;
  }
-- 
2.30.1 (Apple Git-130)


-- 
Serge Petrenko


  reply	other threads:[~2021-12-06  3:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06  3:03 [Tarantool-patches] [PATCH 0/4] replication: introduce applier thread Serge Petrenko via Tarantool-patches
2021-12-06  3:03 ` [Tarantool-patches] [PATCH 1/4] xrow: rework coio_read_xrow to keep parsed input Serge Petrenko via Tarantool-patches
2021-12-06  3:05   ` Serge Petrenko via Tarantool-patches [this message]
2021-12-06  3:03 ` [Tarantool-patches] [PATCH 2/4] applier: reuse input buffer to store row bodies Serge Petrenko via Tarantool-patches
2021-12-06  3:03 ` [Tarantool-patches] [PATCH 3/4] applier: factor replication stream processing out of subscribe() Serge Petrenko via Tarantool-patches
2021-12-06  3:03 ` [Tarantool-patches] [PATCH 4/4] Introduce applier thread Serge Petrenko via Tarantool-patches
2021-12-06  9:59 ` [Tarantool-patches] [PATCH 0/4] replication: introduce " Vladimir Davydov via Tarantool-patches
2021-12-06 10:31   ` Serge Petrenko via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8112214c-cfef-c791-80cf-fe4402540570@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --cc=vdavydov@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/4] xrow: rework coio_read_xrow to keep parsed input' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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