forked from Mirror/wren
Add wrenStringEqualStrLength and wrenStringsEqual.
This commit is contained in:
@ -47,8 +47,7 @@ int wrenSymbolTableFind(const SymbolTable* symbols,
|
||||
// TODO: O(n). Do something better.
|
||||
for (int i = 0; i < symbols->count; i++)
|
||||
{
|
||||
if (symbols->data[i]->length == length &&
|
||||
memcmp(symbols->data[i]->value, name, length) == 0) return i;
|
||||
if(wrenStringEqualStrLength(symbols->data[i], name, length)) return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
@ -1295,11 +1295,7 @@ bool wrenValuesEqual(Value a, Value b)
|
||||
|
||||
case OBJ_STRING:
|
||||
{
|
||||
ObjString* aString = (ObjString*)aObj;
|
||||
ObjString* bString = (ObjString*)bObj;
|
||||
return aString->length == bString->length &&
|
||||
aString->hash == bString->hash &&
|
||||
memcmp(aString->value, bString->value, aString->length) == 0;
|
||||
return wrenStringsEqual((ObjString*)aObj, (ObjString*)bObj);
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define wren_value_h
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wren_common.h"
|
||||
#include "wren_utils.h"
|
||||
@ -785,6 +786,22 @@ static inline bool wrenValuesSame(Value a, Value b)
|
||||
// other values are equal if they are identical objects.
|
||||
bool wrenValuesEqual(Value a, Value b);
|
||||
|
||||
// Returns true is [a] and [str] represent the same string.
|
||||
static inline bool wrenStringEqualStrLength(const ObjString* a,
|
||||
const char* str, size_t length)
|
||||
{
|
||||
return a->length == length &&
|
||||
memcmp(a->value, str, length) == 0;
|
||||
}
|
||||
|
||||
// Returns true is [a] and [b] represent the same string.
|
||||
static inline bool wrenStringsEqual(const ObjString* a, const ObjString* b)
|
||||
{
|
||||
return a == b ||
|
||||
(a->hash == b->hash &&
|
||||
wrenStringEqualStrLength(a, b->value, b->length));
|
||||
}
|
||||
|
||||
// Returns true if [value] is a bool. Do not call this directly, instead use
|
||||
// [IS_BOOL].
|
||||
static inline bool wrenIsBool(Value value)
|
||||
|
||||
Reference in New Issue
Block a user