summaryrefslogtreecommitdiff
path: root/ext/tk
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-09 05:05:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-09 05:05:12 +0000
commitf82df94f390a104be47b57e45801409be23954a9 (patch)
treea12c78756755ebd30bea2cbd7faee137924a18dc /ext/tk
parent3f6401864aad925701804ea003ec834f123dfbc9 (diff)
tcltklib.c: repeated checks and conversions [ci skip]
* ext/tk/tcltklib.c (ip_init): get rid of repeated checks and conversions in StringValueCStr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk')
-rw-r--r--ext/tk/tcltklib.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c
index 721f497ef4..1e425d7654 100644
--- a/ext/tk/tcltklib.c
+++ b/ext/tk/tcltklib.c
@@ -6215,14 +6215,16 @@ ip_init(argc, argv, self)
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 */