From 107c11985f1ae15d28ee4743113f6b91cfef31a8 Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 17 Jul 2015 22:08:49 +0000 Subject: 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 --- signal.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'signal.c') 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; -- cgit v1.2.3