stringChunkListsEq() + fix some i32 compares with u32

This commit is contained in:
Tenari
2026-04-11 10:46:13 -05:00
parent 60330da767
commit 28180886ae
4 changed files with 25 additions and 7 deletions
+1
View File
@@ -707,6 +707,7 @@ fn void stringChunkListAppend(StringArena* a, StringChunkList* list, String stri
fn void stringChunkListDeleteLast(StringArena* a, StringChunkList* list); fn void stringChunkListDeleteLast(StringArena* a, StringChunkList* list);
fn StringChunkList stringChunkListInit(StringArena* a); fn StringChunkList stringChunkListInit(StringArena* a);
fn void stringChunkCopyToBuffer(StringChunkList* list, u8* buffer, u32 len); fn void stringChunkCopyToBuffer(StringChunkList* list, u8* buffer, u32 len);
fn bool stringChunkListsEq(StringChunkList* a, StringChunkList* b);
///// BINARY SERIALIZATION NONSENSE ///// BINARY SERIALIZATION NONSENSE
fn u64 writeU64ToBufferLE(u8* buffer, u64 value); fn u64 writeU64ToBufferLE(u8* buffer, u64 value);
+2 -2
View File
@@ -4,7 +4,7 @@ fn bool stringsEq(String* a, String* b) {
if (a->length != b->length) { if (a->length != b->length) {
return false; return false;
} }
for (i32 i = 0; i < a->length; i++) { for (u32 i = 0; i < a->length; i++) {
if (a->bytes[i] != b->bytes[i]) { if (a->bytes[i] != b->bytes[i]) {
return false; return false;
} }
@@ -16,7 +16,7 @@ fn bool cStringEqString(str a, String* b) {
if (strlen(a) != b->length) { if (strlen(a) != b->length) {
return false; return false;
} }
for (i32 i = 0; i < b->length; i++) { for (u32 i = 0; i < b->length; i++) {
if (a[i] != b->bytes[i]) { if (a[i] != b->bytes[i]) {
return false; return false;
} }
+17
View File
@@ -160,3 +160,20 @@ fn void stringChunkCopyToBuffer(StringChunkList* list, u8* buffer, u32 len) {
buffer[i] = *((char*)(chunk + 1) + (i%STRING_CHUNK_PAYLOAD_SIZE)); buffer[i] = *((char*)(chunk + 1) + (i%STRING_CHUNK_PAYLOAD_SIZE));
} }
} }
fn bool stringChunkListsEq(StringChunkList* a, StringChunkList* b) {
if (a->total_size != b->total_size) return false;
StringChunk* chunk_a = a->first;
StringChunk* chunk_b = b->first;
for (u32 i = 0; i < a->total_size; i++) {
if (i > 0 && i % STRING_CHUNK_PAYLOAD_SIZE == 0) {
chunk_a = chunk_a->next;
chunk_b = chunk_b->next;
}
u8 a_char = *((char*)(chunk_a + 1) + (i%STRING_CHUNK_PAYLOAD_SIZE));
u8 b_char = *((char*)(chunk_b + 1) + (i%STRING_CHUNK_PAYLOAD_SIZE));
if (a_char != b_char) return false;
}
return true;
}
+5 -5
View File
@@ -191,7 +191,7 @@ fn bool osFileCreate(String filename) {
return true; return true;
*/ */
bool result = true; bool result = true;
size_t handle = open((str)filename.bytes, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); i32 handle = open((str)filename.bytes, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (handle == -1) { if (handle == -1) {
result = false; result = false;
} }
@@ -215,7 +215,7 @@ fn bool osFileCreateWrite(String filename, String data) {
return result; return result;
*/ */
bool result = true; bool result = true;
size_t handle = open( i32 handle = open(
(str)filename.bytes, (str)filename.bytes,
O_RDWR | O_CREAT | O_TRUNC, O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IRGRP | S_IROTH S_IRUSR | S_IRGRP | S_IROTH
@@ -238,7 +238,7 @@ fn bool osFileWrite(String filename, String data) {
close(handle); close(handle);
*/ */
bool result = true; bool result = true;
size_t handle = open((str) filename.bytes, O_RDWR | O_TRUNC, S_IRUSR | S_IRGRP | S_IROTH); i32 handle = open((str) filename.bytes, O_RDWR | O_TRUNC, S_IRUSR | S_IRGRP | S_IROTH);
if (handle == -1) result = false; if (handle == -1) result = false;
write(handle, data.bytes, data.length); write(handle, data.bytes, data.length);
close(handle); close(handle);
@@ -246,7 +246,7 @@ fn bool osFileWrite(String filename, String data) {
} }
fn Resulti64 osFileOpenForWriting(String filename) { fn Resulti64 osFileOpenForWriting(String filename) {
size_t handle = open((str)filename.bytes, O_WRONLY | O_APPEND, S_IRUSR | S_IRGRP | S_IROTH); i32 handle = open((str)filename.bytes, O_WRONLY | O_APPEND, S_IRUSR | S_IRGRP | S_IROTH);
Resulti64 result = { Resulti64 result = {
.success = handle != -1, .success = handle != -1,
.value = (i64)handle, .value = (i64)handle,
@@ -266,7 +266,7 @@ fn Resulti64 osFileClose(Resulti64 handle) {
fn bool osFileWriteOpenFile(Resulti64 handle, String data) { fn bool osFileWriteOpenFile(Resulti64 handle, String data) {
assert(handle.success == true); assert(handle.success == true);
i32 wrote_this_round = 0; i32 wrote_this_round = 0;
for (i32 bytes_written = 0; bytes_written < data.length; bytes_written += wrote_this_round) { for (u32 bytes_written = 0; bytes_written < data.length; bytes_written += wrote_this_round) {
wrote_this_round = write((size_t)handle.value, data.bytes + bytes_written, data.length - bytes_written); wrote_this_round = write((size_t)handle.value, data.bytes + bytes_written, data.length - bytes_written);
if (wrote_this_round == -1) return false; if (wrote_this_round == -1) return false;
} }