From 335716b81d99c7476e68979fe48b20b0f2bfeeee Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 28 Oct 2016 14:45:54 +0000 Subject: Add obvious optimizations to [join] implementation. --- generic/tclCmdIL.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index bb3c9b7..7f4ca1d 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -2173,6 +2173,16 @@ Tcl_JoinObjCmd( return TCL_ERROR; } + if (listLen == 0) { + /* No elements to join; default empty result is correct. */ + return TCL_OK; + } + if (listLen == 1) { + /* One element; return it */ + Tcl_SetObjResult(interp, elemPtrs[0]); + return TCL_OK; + } + joinObjPtr = (objc == 2) ? Tcl_NewStringObj(" ", 1) : objv[2]; Tcl_IncrRefCount(joinObjPtr); -- cgit v0.12