mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Tweaked refstring, thanks SchuperJesse!
This commit is contained in:
@@ -19,7 +19,7 @@ void setRefStringAllocatorFn(RefStringAllocatorFn allocator) {
|
|||||||
|
|
||||||
//API
|
//API
|
||||||
RefString* createRefString(char* cstring) {
|
RefString* createRefString(char* cstring) {
|
||||||
int length = strlen(cstring);
|
int length = strnlen(cstring, 4096);
|
||||||
|
|
||||||
return createRefStringLength(cstring, length);
|
return createRefStringLength(cstring, length);
|
||||||
}
|
}
|
||||||
@@ -39,13 +39,11 @@ RefString* createRefStringLength(char* cstring, int length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deleteRefString(RefString* refString) {
|
void deleteRefString(RefString* refString) {
|
||||||
if (refString->refcount > 0) {
|
|
||||||
//decrement, then check
|
//decrement, then check
|
||||||
refString->refcount--;
|
refString->refcount--;
|
||||||
if (refString->refcount <= 0) {
|
if (refString->refcount <= 0) {
|
||||||
allocate(refString, sizeof(int) * 2 + sizeof(char) * refString->length + 1, 0);
|
allocate(refString, sizeof(int) * 2 + sizeof(char) * refString->length + 1, 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int countRefString(RefString* refString) {
|
int countRefString(RefString* refString) {
|
||||||
@@ -88,7 +86,7 @@ bool equalsRefString(RefString* lhs, RefString* rhs) {
|
|||||||
|
|
||||||
bool equalsRefStringCString(RefString* lhs, char* cstring) {
|
bool equalsRefStringCString(RefString* lhs, char* cstring) {
|
||||||
//get the rhs length
|
//get the rhs length
|
||||||
int length = strlen(cstring);
|
int length = strnlen(cstring, 4096);
|
||||||
|
|
||||||
//different length
|
//different length
|
||||||
if (lhs->length != length) {
|
if (lhs->length != length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user