From 00864a06a860c31f0b139a543f07d94dd37c8a59 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 13 Mar 2011 09:54:37 +0000 Subject: avoid potential RString -> C-string conversions Unlikely, but it may make a difference somewhere... --- ext/clogger_ext/clogger.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index 0adefa4..9fe1e58 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -888,23 +888,25 @@ static VALUE respond_to(VALUE self, VALUE method) static VALUE to_path(VALUE self) { struct clogger *c = clogger_get(self); - VALUE path = rb_funcall(c->body, to_path_id, 0); struct stat sb; int rv; - unsigned devfd; - const char *cpath = StringValueCStr(path); + VALUE path = rb_funcall(c->body, to_path_id, 0); /* try to avoid an extra path lookup */ - if (rb_respond_to(c->body, to_io_id)) + if (rb_respond_to(c->body, to_io_id)) { rv = fstat(my_fileno(c->body), &sb); - /* - * Rainbows! can use "/dev/fd/%u" in to_path output to avoid - * extra open() syscalls, too. - */ - else if (sscanf(cpath, "/dev/fd/%u", &devfd) == 1) - rv = fstat((int)devfd, &sb); - else - rv = stat(cpath, &sb); + } else { + const char *cpath = StringValueCStr(path); + unsigned devfd; + /* + * Rainbows! can use "/dev/fd/%u" in to_path output to avoid + * extra open() syscalls, too. + */ + if (sscanf(cpath, "/dev/fd/%u", &devfd) == 1) + rv = fstat((int)devfd, &sb); + else + rv = stat(cpath, &sb); + } /* * calling this method implies the web server will bypass -- cgit v1.2.3-24-ge0c7