[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] Incremental search
- To: libevent-users@xxxxxxxxxxxxx
- Subject: Re: [Libevent-users] Incremental search
- From: Azat Khuzhin <a3at.mail@xxxxxxxxx>
- Date: Sun, 17 Dec 2017 00:09:32 +0300
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Sat, 16 Dec 2017 16:09:40 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=nkIA7piqIi1oDg/eyjXHcbfnVm4SFd7dJ9KxyRRv+v0=; b=XCC917Sbqq5pD7CZA3mwUTB3R+wVN+HpRhDgIgMECVRIsLDW44K/A1Ie5hW3fD2VYD H/2QKRWIk2DWN3rp8eSe4WpS83oBUJGp4ZTLo9uQofRToIj/pk2CYnzkF3X2GUzLONN+ KF7zaWKODB7AGOU67v7qIXDQVoodN+OkfV3C7RLWClPEKXmNBsr5jgXO7a/DTVfO0uGm 17Xb4/Q+htBAZE1IKBCoylPWp3U70QHrRLk5gV1hWHuAugE6Gq6aZjhOZPti0zKJ9ayh Z3kheC0g30JIG8aIiUiudcfhKqzq71ivD7IQfO+qbYou9wcNzVN1W404BHsDytBGhYSa y/JQ==
- In-reply-to: <20171215110215.GA3189@orkisz>
- References: <20171215110215.GA3189@orkisz>
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
Hi!
> request_line = evbuffer_readln(buf, &len, EVBUFFER_EOL_CRLF);
Yes, this is not optimal thing to do (though most of the time this
will be enough).
> If I see correctly in case of evbuffer_readln() the search always
> happens from the beginning of the chunks chain.
Yep
> In case of evbuffer_search_range() theoretically I can (optionally)
> provide the start evbuffer_ptr[2] but I have a problem finding an
> efficient way to update that pointer after every negative result.
I don't see problem in your code with updating it, it looks good to me.
> The only concept I came up with would look something like this:
> #v+
> tmp_ptr = evbuffer_search_range (buf, "\t", 1, incr_ptr.pos != -1 ? &incr_ptr : NULL, NULL);
> if (tmp_ptr.pos == -1) {
> // negative result
>
> // quick, read directly from an internal field
> last_char = evbuffer_get_length (buf) - 1;
> if (incr_ptr.pos != -1)
> // requires second (after evbuffer_search_range) partial chain traversal
> evbuffer_ptr_set (buf, &incr_ptr, last_char - prev_last_char, EVBUFFER_PTR_ADD);
> else
> // requires second (after evbuffer_search_range) chain traversal
> evbuffer_ptr_set (buf, &incr_ptr, last_char, EVBUFFER_PTR_SET);
> prev_last_char = last_char;
EVBUFFER_PTR_ADD is just to optimize code yep? (since EVBUFFER_PTR_SET
iterate over chunks)
(and evbuffer_ptr_set()+evbuffer_search_range() is not compatible with
evbuffer_pullup() and any other API that playing with chains)
> } else {
> // a hit
>
> incr_ptr.pos = -1;
So here you don't remove that part of the buffer (the one from the
beginning to the delimiter), yes?
> }
> #v-
> On the other hand this would cause one more (partial) traversal of the
> chain every time data arrives. Probably still more efficient because
> it's just hopping through a list and simple arithmetics compared to the
> naive readln-like evbuffer_search() solution.
Indeed, and if data arrives in a big chunks than you shouldn't see any overhead.
> It also contains a bug of checking the last seen character twice.
> Position after the last character is represented with chain == NULL, so
> it would be unusable with EVBUFFER_PTR_ADD.
Yeah, and we can't change evbuffer_ptr_set() since this will break
compatibility.
Maybe introduce some EVBUFFER_PTR_END that will set the ptr to the end
(real one), and this should be enough for incremental search?
(but I wasn't thinking about this enough time, so don't consider this
as some final decision).
> Probably it would be perfect if an alternative evbuffer_search_range()
> API existed with a non-const start/end evbuffer_ptr updated on every
> call so one can continue the search from the last seen position.
I guess so, but it doesn't exists for now, if you are interested in
contribute this feature, please go ahead!
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.