mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
f2feaafe0c
commit
a3dca0f594
2 changed files with 14 additions and 7 deletions
|
@ -1,3 +1,7 @@
|
|||
Sat Jul 18 07:04:24 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* signal.c (trap_handler): cleanup to use RSTRING_GETMEM + memcmp
|
||||
|
||||
Sat Jul 18 02:53:06 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* io.c (argf_read_nonblock): support `exception: false'
|
||||
|
|
17
signal.c
17
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;
|
||||
|
|
Loading…
Reference in a new issue