diff options
| author | Arslaan Pathan <[email protected]> | 2026-10-04 19:48:30 +1300 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-10-04 19:48:30 +1300 |
| commit | b50119031f1b1b4935a20837ae931f0cc0f1167e (patch) | |
| tree | bd82d26d07e909d4b7463321b07d9fafc1fd6e1a /src/String.m | |
| parent | 4c8f79bd52bb9effd00fe8347dd910cbec646e94 (diff) | |
| download | Paradox-b50119031f1b1b4935a20837ae931f0cc0f1167e.tar.xz Paradox-b50119031f1b1b4935a20837ae931f0cc0f1167e.zip | |
Diffstat (limited to 'src/String.m')
| -rw-r--r-- | src/String.m | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/String.m b/src/String.m index 7d5d4d8..cc91745 100644 --- a/src/String.m +++ b/src/String.m @@ -25,15 +25,24 @@ if (cstring == NULL) cstring = ""; - _length = strlen(cstring); - _bytes = malloc(_length + 1); - memcpy(_bytes, cstring, _length + 1); + size_t length = strlen(cstring); + + flags = 0; // ASCII + flags |= PXStringFlagOwned; // OUR string (not compiler's) + len = (uint32_t)length; + size = (uint32_t)length; + hash = 0; // implement hashes later + + _bytes = malloc(length + 1); + memcpy((char *)_bytes, cstring, length + 1); } return self; } - (void)dealloc { - free(_bytes); + if (flags & PXStringFlagOwned) + free((void *)_bytes); + [super dealloc]; } @@ -42,18 +51,18 @@ return _bytes; } -- (size_t)length { - return _length; +- (uint32_t)length { + return len; } - (BOOL)isEqual:(PXString *)string { if (self == string) return YES; - if (string == nil || _length != string->_length) + if (string == nil || len != string->len) return NO; - return (memcmp(_bytes, string->_bytes, _length) == 0); + return (memcmp(_bytes, string->_bytes, size) == 0); } @end |
