Index: generic/nsf.c =================================================================== diff -u -r2ba521e3dfbb1294908b51ed8e13dab5adc3ca03 -re639a46f30e0e0c10dc84c898e828b9abe9298d9 --- generic/nsf.c (.../nsf.c) (revision 2ba521e3dfbb1294908b51ed8e13dab5adc3ca03) +++ generic/nsf.c (.../nsf.c) (revision e639a46f30e0e0c10dc84c898e828b9abe9298d9) @@ -460,7 +460,7 @@ */ static void ParseContextInit(ParseContext *pcPtr, int objc, NsfObject *object, Tcl_Obj *procName) { - if (objc < PARSE_CONTEXT_PREALLOC) { + if (likely(objc < PARSE_CONTEXT_PREALLOC)) { /* the single larger memset below .... */ memset(pcPtr, 0, sizeof(ParseContext)); /* ... is faster than the two smaller memsets below */ @@ -510,23 +510,23 @@ /*NsfPrintObjv("BEFORE: ", pcPtr->objc, pcPtr->full_objv);*/ - if (requiredSize >= PARSE_CONTEXT_PREALLOC) { + if (unlikely(requiredSize >= PARSE_CONTEXT_PREALLOC)) { if (pcPtr->objv == &pcPtr->objv_static[1]) { /* realloc from preallocated memory */ pcPtr->full_objv = (Tcl_Obj **)ckalloc(sizeof(Tcl_Obj *) * requiredSize); pcPtr->flags = (int *) ckalloc(sizeof(int) * requiredSize); MEM_COUNT_ALLOC("pcPtr.objv", pcPtr->full_objv); memcpy(pcPtr->full_objv, &pcPtr->objv_static[0], sizeof(Tcl_Obj *) * PARSE_CONTEXT_PREALLOC); memcpy(pcPtr->flags, &pcPtr->flags_static[0], sizeof(int) * PARSE_CONTEXT_PREALLOC); - /*fprintf(stderr, "extend %p alloc %d new objv=%p pcPtr %p\n", - pcPtr, requiredSize, pcPtr->full_objv, pcPtr);*/ + /* fprintf(stderr, "ParseContextExtendObjv: extend %p alloc %d new objv=%p pcPtr %p\n", + pcPtr, requiredSize, pcPtr->full_objv, pcPtr);*/ pcPtr->status |= NSF_PC_STATUS_FREE_OBJV; } else { /* realloc from mallocated memory */ pcPtr->full_objv = (Tcl_Obj **)ckrealloc((char *)pcPtr->full_objv, sizeof(Tcl_Obj *) * requiredSize); pcPtr->flags = (int *) ckrealloc((char *)pcPtr->flags, sizeof(int) * requiredSize); - /*fprintf(stderr, "extend %p realloc %d new objv=%p pcPtr %p\n", + /*fprintf(stderr, "ParseContextExtendObjv: extend %p realloc %d new objv=%p pcPtr %p\n", pcPtr, requiredSize, pcPtr->full_objv, pcPtr);*/ } pcPtr->objv = &pcPtr->full_objv[1]; @@ -587,7 +587,6 @@ * (1) make sure, that the status correctly reflects MUST_DECR */ int i; - if (status == 0 || (status & NSF_PC_STATUS_MUST_DECR) == 0) { for (i = 0; i < pcPtr->objc - 1; i++) { assert((pcPtr->flags[i] & NSF_PC_MUST_DECR) == 0); @@ -617,7 +616,7 @@ } #endif - if (status) { + if (unlikely(status)) { if (status & NSF_PC_STATUS_MUST_DECR) { int i; /*fprintf(stderr, "ParseContextRelease %p loop from 0 to %d\n", pcPtr, pcPtr->objc-1);*/ @@ -637,7 +636,7 @@ * Objv can be separately extended; also flags are extend when this * happens. */ - if (status & NSF_PC_STATUS_FREE_OBJV) { + if (unlikely(status & NSF_PC_STATUS_FREE_OBJV)) { /*fprintf(stderr, "ParseContextRelease %p free %p %p\n", pcPtr, pcPtr->full_objv, pcPtr->clientData);*/ MEM_COUNT_FREE("pcPtr.objv", pcPtr->full_objv); @@ -670,7 +669,7 @@ tov[0] = object->cmdName; tov[1] = methodObj; - if (objc>2) { + if (likely(objc>2)) { memcpy(tov+2, objv, sizeof(Tcl_Obj *)*(objc-2)); } @@ -1100,7 +1099,7 @@ /*fprintf(stderr, "NsfCleanupObject obj refCount of %p after decr %d id %p interp %p flags %.6x\n", object, object->refCount, object->id, object->teardown, object->flags);*/ - if (object->refCount <= 0) { + if (unlikely(object->refCount <= 0)) { /*fprintf(stderr, "NsfCleanupObject %p refcount %d\n", object, object->refCount);*/ assert(object->refCount == 0); assert(object->flags & NSF_DELETED); @@ -1150,7 +1149,7 @@ Tcl_ObjType CONST86 *cmdType = objPtr->typePtr; if (cmdType == Nsf_OT_tclCmdNameType) { Tcl_Command cmd = Tcl_GetCommandFromObj(interp, objPtr); - if (cmd) { + if (likely(cmd != NULL)) { NsfObject *object = NsfGetObjectFromCmdPtr(cmd); if (object) { *objectPtr = object; @@ -1402,16 +1401,16 @@ NsfClass *cl; Tcl_DString ds, *dsPtr = &ds; - if ((pPtr->flags & NSF_ARG_BASECLASS) && !IsBaseClass((NsfClass *)object)) { + if (unlikely(pPtr->flags & NSF_ARG_BASECLASS) && !IsBaseClass((NsfClass *)object)) { what = "baseclass"; goto type_error; } - if ((pPtr->flags & NSF_ARG_METACLASS) && !IsMetaClass(interp, (NsfClass *)object, 1)) { + if (unlikely(pPtr->flags & NSF_ARG_METACLASS) && !IsMetaClass(interp, (NsfClass *)object, 1)) { what = "metaclass"; goto type_error; } - if (pPtr->converterArg == NULL) { + if (likely(pPtr->converterArg == NULL)) { return TCL_OK; } if ((GetClassFromObj(interp, pPtr->converterArg, &cl, 0) == TCL_OK) @@ -2924,8 +2923,8 @@ /* fprintf(stderr, ".. search #local vars %d for %s\n", localCt, varName);*/ for (i=0 ; iparamDefs; } return NULL; @@ -15430,7 +15425,7 @@ /* * If argument checking is turned off, and we do not have an converter, do nothing. */ - if (doCheck == 0 && (pPtr->flags & (NSF_ARG_IS_CONVERTER|NSF_ARG_INITCMD)) == 0) { + if (unlikely(doCheck == 0) && (pPtr->flags & (NSF_ARG_IS_CONVERTER|NSF_ARG_INITCMD)) == 0) { /*fprintf(stderr, "*** omit argument check for arg %s flags %.6x\n", pPtr->name, pPtr->flags);*/ *clientData = ObjStr(objPtr); return TCL_OK; @@ -15536,7 +15531,7 @@ * In case the value is a switch and NSF_PC_INVERT_DEFAULT is set, we * take the default and invert the value in place. */ - if ((pcPtr->flags[i] & NSF_PC_INVERT_DEFAULT)) { + if (unlikely(pcPtr->flags[i] & NSF_PC_INVERT_DEFAULT)) { int bool; Tcl_GetBooleanFromObj(interp, pPtr->defaultValue, &bool); pcPtr->objv[i] = Tcl_NewBooleanObj(!bool); @@ -15566,10 +15561,10 @@ pcPtr->flags[i] |= NSF_PC_IS_DEFAULT; /* Is it necessary to substitute the default value? */ - if (pPtr->flags & NSF_ARG_SUBST_DEFAULT) { + if (unlikely(pPtr->flags & NSF_ARG_SUBST_DEFAULT)) { Tcl_Obj *obj = Tcl_SubstObj(interp, newValue, TCL_SUBST_ALL); - if (obj) { + if (likely(obj != NULL)) { newValue = obj; } else { pcPtr->flags[i] = 0; @@ -15594,7 +15589,7 @@ /* * Check the default value if necessary */ - if (pPtr->type || (pPtr->flags & NSF_ARG_MULTIVALUED)) { + if (pPtr->type || unlikely(pPtr->flags & NSF_ARG_MULTIVALUED)) { int mustDecrList = 0; if (unlikely(ArgumentCheck(interp, newValue, pPtr, RUNTIME_STATE(interp)->doCheckArguments, @@ -15606,7 +15601,7 @@ return TCL_ERROR; } - if (pcPtr->objv[i] != newValue) { + if (unlikely(pcPtr->objv[i] != newValue)) { /* * The output Tcl_Obj differs from the input, so the * Tcl_Obj was converted; in case we have set prevously @@ -15632,7 +15627,7 @@ pPtr->name, ObjStr(pPtr->defaultValue), pPtr->type);*/ assert(pPtr->type ? pPtr->defaultValue == NULL : 1); } - } else if (pPtr->flags & NSF_ARG_REQUIRED) { + } else if (unlikely(pPtr->flags & NSF_ARG_REQUIRED)) { Tcl_Obj *paramDefsObj = NsfParamDefsSyntax(ifd); NsfPrintError(interp, "required argument '%s' is missing, should be:\n\t%s%s%s %s",