kcar RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: kcar-public@bogomips.org
Subject: [PATCH 1/7] introduce new str_new_dd_freeze internal function
Date: Wed, 19 Apr 2017 22:30:19 +0000	[thread overview]
Message-ID: <20170419223025.8093-2-e@80x24.org> (raw)
In-Reply-To: <20170419223025.8093-1-e@80x24.org>

This seems like it will be a common pattern to create
and immediately dedupe a string.  In the future, we may
be able to save some memory by eliding temporary object
creation or releasing heap memory via rb_str_resize(..., 0)
---
 ext/kcar/kcar.rl | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ext/kcar/kcar.rl b/ext/kcar/kcar.rl
index cbcfa97..79f65db 100644
--- a/ext/kcar/kcar.rl
+++ b/ext/kcar/kcar.rl
@@ -106,6 +106,11 @@ static VALUE str_dd_freeze(VALUE str)
   return str;
 }
 
+static VALUE str_new_dd_freeze(const char *ptr, long len)
+{
+  return str_dd_freeze(rb_str_new(ptr, len));
+}
+
 static VALUE stripped_str_new(const char *str, long len)
 {
   long end;
@@ -161,7 +166,7 @@ status_phrase(struct http_parser *hp, VALUE hdr, const char *ptr, size_t len)
 {
   long nr;
 
-  hp->status = str_dd_freeze(rb_str_new(ptr, len));
+  hp->status = str_new_dd_freeze(ptr, len);
 
   /* RSTRING_PTR is null terminated, ptr is not */
   nr = strtol(RSTRING_PTR(hp->status), NULL, 10);
@@ -238,7 +243,7 @@ static void write_value(VALUE hdr, struct http_parser *hp,
   vlen = LEN(mark, p);
   VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE);
   VALIDATE_MAX_LENGTH(flen, FIELD_NAME);
-  f = str_dd_freeze(rb_str_new(fptr, (long)flen));
+  f = str_new_dd_freeze(fptr, (long)flen);
   v = stripped_str_new(vptr, (long)vlen);
 
   /* needs more tests for error-checking here */
-- 
EW


  reply	other threads:[~2017-04-19 22:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-19 22:30 [PATCH 0/7] request parsing bits Eric Wong
2017-04-19 22:30 ` Eric Wong [this message]
2017-04-19 22:30 ` [PATCH 2/7] begin implementing request parsing Eric Wong
2017-04-27 18:00   ` Eric Wong
2017-04-19 22:30 ` [PATCH 3/7] favor bitfields instead flags + macros Eric Wong
2017-04-19 22:30 ` [PATCH 4/7] implement request parsing with tests Eric Wong
2017-04-19 22:30 ` [PATCH 5/7] pkg.mk: enable warnings by default for tests Eric Wong
2017-04-19 22:30 ` [PATCH 6/7] filter_body: rename variables to be like memcpy(3) Eric Wong
2017-04-19 22:30 ` [PATCH 7/7] flesh out filter_body for request parsing Eric Wong

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

  List information: https://yhbt.net/kcar/

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

  git send-email \
    --in-reply-to=20170419223025.8093-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=kcar-public@bogomips.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kcar.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).