From 5339e48e6f3499e2fccf9b57fed6e461c7ce131c Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Sat, 11 Jan 2014 21:53:17 +1000 Subject: [PATCH] jim.c: simplifiy Jim_StrEqObj() And use it from the expr evaluator Signed-off-by: Steve Bennett --- jim.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/jim.c b/jim.c index a6d9ac6..6204997 100644 --- a/jim.c +++ b/jim.c @@ -2524,16 +2524,16 @@ void Jim_AppendStrings(Jim_Interp *interp, Jim_Obj *objPtr, ...) int Jim_StringEqObj(Jim_Obj *aObjPtr, Jim_Obj *bObjPtr) { - const char *aStr, *bStr; - int aLen, bLen; - - if (aObjPtr == bObjPtr) + if (aObjPtr == bObjPtr) { return 1; - aStr = Jim_GetString(aObjPtr, &aLen); - bStr = Jim_GetString(bObjPtr, &bLen); - if (aLen != bLen) - return 0; - return JimStringCompare(aStr, aLen, bStr, bLen) == 0; + } + else { + int Alen, Blen; + const char *sA = Jim_GetString(aObjPtr, &Alen); + const char *sB = Jim_GetString(bObjPtr, &Blen); + + return Alen == Blen && memcmp(sA, sB, Alen) == 0; + } } /** @@ -8072,19 +8072,12 @@ static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprState *e) switch (e->opcode) { case JIM_EXPROP_STREQ: - case JIM_EXPROP_STRNE: { - int Alen, Blen; - const char *sA = Jim_GetString(A, &Alen); - const char *sB = Jim_GetString(B, &Blen); - - if (e->opcode == JIM_EXPROP_STREQ) { - wC = (Alen == Blen && memcmp(sA, sB, Alen) == 0); - } - else { - wC = (Alen != Blen || memcmp(sA, sB, Alen) != 0); + case JIM_EXPROP_STRNE: + wC = Jim_StringEqObj(A, B); + if (e->opcode == JIM_EXPROP_STRNE) { + wC = !wC; } break; - } case JIM_EXPROP_STRIN: wC = JimSearchList(interp, B, A); break; -- 2.11.4.GIT