ruby-changes:43770
From: nobu <ko1@a...>
Date: Tue, 9 Aug 2016 14:11:32 +0900 (JST)
Subject: [ruby-changes:43770] nobu:r55843 (trunk): tcltklib.c: repeated checks and conversions [ci skip]
nobu 2016-08-09 14:05:12 +0900 (Tue, 09 Aug 2016) New Revision: 55843 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55843 Log: tcltklib.c: repeated checks and conversions [ci skip] * ext/tk/tcltklib.c (ip_init): get rid of repeated checks and conversions in StringValueCStr. Modified files: trunk/ext/tk/tcltklib.c Index: ext/tk/tcltklib.c =================================================================== --- ext/tk/tcltklib.c (revision 55842) +++ ext/tk/tcltklib.c (revision 55843) @@ -6215,14 +6215,16 @@ ip_init(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6215 case 1: /* argv0 */ if (!NIL_P(argv0)) { - if (strncmp(StringValueCStr(argv0), "-e", 3) == 0 - || strncmp(StringValueCStr(argv0), "-", 2) == 0) { - Tcl_SetVar(ptr->ip, "argv0", "ruby", TCL_GLOBAL_ONLY); + const char *name = StringValueCStr(argv0); + long len = RSTRING_LEN(argv0); + int flag = TCL_GLOBAL_ONLY; + if ((len == 2 && memcmp(name, "-e", 2) == 0) + || (len == 1 && memcmp(name, "-", 1) == 0)) { + name = "ruby"; } else { - /* Tcl_SetVar(ptr->ip, "argv0", StringValueCStr(argv0), 0); */ - Tcl_SetVar(ptr->ip, "argv0", StringValueCStr(argv0), - TCL_GLOBAL_ONLY); + /* flag = 0; */ } + Tcl_SetVar(ptr->ip, "argv0", name, flag); } case 0: /* no args */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/