diff options
author | Eric Wong <normalperson@yhbt.net> | 2014-12-28 01:33:28 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2014-12-28 01:33:28 +0000 |
commit | e11df63b53f20834687dafdbd3b427d24c27cac0 (patch) | |
tree | cfa3bf46fe0c3271cf1bd800b56e3af6eba88165 | |
parent | 159c1ec26428bc6206ea4ac8dcc3f4ea1569793a (diff) | |
download | sleepy_penguin-e11df63b53f20834687dafdbd3b427d24c27cac0.tar.gz |
We'll prefer using rb_str_new2 instead of rb_str_new(...,strlen) to save binary size. While we're at it, explain why we cannot take e->len into account for plain-old rb_str_new.
-rw-r--r-- | ext/sleepy_penguin/inotify.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/sleepy_penguin/inotify.c b/ext/sleepy_penguin/inotify.c index 1f2d4ac..b324227 100644 --- a/ext/sleepy_penguin/inotify.c +++ b/ext/sleepy_penguin/inotify.c @@ -124,8 +124,13 @@ static VALUE event_new(struct inotify_event *e) VALUE cookie = UINT2NUM(e->cookie); VALUE name; - /* name may be zero-padded, so we do strlen() */ - name = e->len ? rb_str_new(e->name, strlen(e->name)) : Qnil; + /* + * e->name is zero-padded, so we may use rb_str_new2. + * We do not use rb_str_new(e->name, e->len) because + * e->len counts all \0 padding bytes, and there may be + * multiple padding bytes + */ + name = e->len ? rb_str_new2(e->name) : Qnil; return rb_struct_new(cEvent, wd, mask, cookie, name); } |