summaryrefslogtreecommitdiff
path: root/signal.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-17 22:08:49 (GMT)
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-17 22:08:49 (GMT)
commita3dca0f59495d8a26aa503ff3d52ba249a6aa65c (patch)
tree9e935ead0da391f34162bfe1813d5edbb11feb5d /signal.c
parentf2feaafe0cb35c83dd2bf8c73ad9da20ddc426b8 (diff)
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
Diffstat (limited to 'signal.c')
-rw-r--r--signal.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/signal.c b/signal.c
index 40caaa6..5d5cb6b 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;