From a3dca0f59495d8a26aa503ff3d52ba249a6aa65c Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 17 Jul 2015 22:08:49 +0000 Subject: [PATCH] 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ signal.c | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a4f14b61e..e0b2c7d187 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Jul 18 07:04:24 2015 Eric Wong + + * signal.c (trap_handler): cleanup to use RSTRING_GETMEM + memcmp + Sat Jul 18 02:53:06 2015 Eric Wong * io.c (argf_read_nonblock): support `exception: false' diff --git a/signal.c b/signal.c index 40caaa660c..5d5cb6b2b6 100644 --- a/signal.c +++ b/signal.c @@ -1086,40 +1086,43 @@ trap_handler(VALUE *cmd, int sig) 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;