ruby-changes:39206
From: normal <ko1@a...>
Date: Sat, 18 Jul 2015 07:10:09 +0900 (JST)
Subject: [ruby-changes:39206] normal:r51287 (trunk): signal.c (trap_handler): cleanup to use RSTRING_GETMEM + memcmp
normal 2015-07-18 07:08:49 +0900 (Sat, 18 Jul 2015) New Revision: 51287 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51287 Log: signal.c (trap_handler): cleanup to use RSTRING_GETMEM + memcmp strncmp is unnecessary since the switch/case statement already checks length of the string; so use memcmp. This makes for a small reduction in binary size on 32-bit x86: text data bss dec hex filename 2847473 12360 30632 2890465 2c1ae1 ruby.before 2847313 12328 30632 2890273 2c1a21 ruby.after Modified files: trunk/ChangeLog trunk/signal.c Index: ChangeLog =================================================================== --- ChangeLog (revision 51286) +++ ChangeLog (revision 51287) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jul 18 07:04:24 2015 Eric Wong <e@8...> + + * signal.c (trap_handler): cleanup to use RSTRING_GETMEM + memcmp + Sat Jul 18 02:53:06 2015 Eric Wong <e@8...> * io.c (argf_read_nonblock): support `exception: false' Index: signal.c =================================================================== --- signal.c (revision 51286) +++ signal.c (revision 51287) @@ -1086,40 +1086,43 @@ trap_handler(VALUE *cmd, int sig) https://github.com/ruby/ruby/blob/trunk/signal.c#L1086 if (!command) rb_raise(rb_eArgError, "bad handler"); } if (!NIL_P(command)) { + const char *cptr; + long len; SafeStringValue(command); /* taint check */ *cmd = command; - switch (RSTRING_LEN(command)) { + RSTRING_GETMEM(command, cptr, len); + switch (len) { case 0: goto sig_ign; break; case 14: - if (strncmp(RSTRING_PTR(command), "SYSTEM_DEFAULT", 14) == 0) { + if (memcmp(cptr, "SYSTEM_DEFAULT", 14) == 0) { func = SIG_DFL; *cmd = 0; } break; case 7: - if (strncmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) { + if (memcmp(cptr, "SIG_IGN", 7) == 0) { sig_ign: func = SIG_IGN; *cmd = Qtrue; } - else if (strncmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) { + else if (memcmp(cptr, "SIG_DFL", 7) == 0) { sig_dfl: func = default_handler(sig); *cmd = 0; } - else if (strncmp(RSTRING_PTR(command), "DEFAULT", 7) == 0) { + else if (memcmp(cptr, "DEFAULT", 7) == 0) { goto sig_dfl; } break; case 6: - if (strncmp(RSTRING_PTR(command), "IGNORE", 6) == 0) { + if (memcmp(cptr, "IGNORE", 6) == 0) { goto sig_ign; } break; case 4: - if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) { + if (memcmp(cptr, "EXIT", 4) == 0) { *cmd = Qundef; } break; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/