stringChunkListsEq() + fix some i32 compares with u32
This commit is contained in:
@@ -707,6 +707,7 @@ fn void stringChunkListAppend(StringArena* a, StringChunkList* list, String stri
|
||||
fn void stringChunkListDeleteLast(StringArena* a, StringChunkList* list);
|
||||
fn StringChunkList stringChunkListInit(StringArena* a);
|
||||
fn void stringChunkCopyToBuffer(StringChunkList* list, u8* buffer, u32 len);
|
||||
fn bool stringChunkListsEq(StringChunkList* a, StringChunkList* b);
|
||||
|
||||
///// BINARY SERIALIZATION NONSENSE
|
||||
fn u64 writeU64ToBufferLE(u8* buffer, u64 value);
|
||||
|
||||
@@ -4,7 +4,7 @@ fn bool stringsEq(String* a, String* b) {
|
||||
if (a->length != b->length) {
|
||||
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]) {
|
||||
return false;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ fn bool cStringEqString(str a, String* b) {
|
||||
if (strlen(a) != b->length) {
|
||||
return false;
|
||||
}
|
||||
for (i32 i = 0; i < b->length; i++) {
|
||||
for (u32 i = 0; i < b->length; i++) {
|
||||
if (a[i] != b->bytes[i]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -160,3 +160,20 @@ fn void stringChunkCopyToBuffer(StringChunkList* list, u8* buffer, u32 len) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ fn bool osFileCreate(String filename) {
|
||||
return 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) {
|
||||
result = false;
|
||||
}
|
||||
@@ -215,7 +215,7 @@ fn bool osFileCreateWrite(String filename, String data) {
|
||||
return result;
|
||||
*/
|
||||
bool result = true;
|
||||
size_t handle = open(
|
||||
i32 handle = open(
|
||||
(str)filename.bytes,
|
||||
O_RDWR | O_CREAT | O_TRUNC,
|
||||
S_IRUSR | S_IRGRP | S_IROTH
|
||||
@@ -238,7 +238,7 @@ fn bool osFileWrite(String filename, String data) {
|
||||
close(handle);
|
||||
*/
|
||||
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;
|
||||
write(handle, data.bytes, data.length);
|
||||
close(handle);
|
||||
@@ -246,7 +246,7 @@ fn bool osFileWrite(String filename, String data) {
|
||||
}
|
||||
|
||||
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 = {
|
||||
.success = handle != -1,
|
||||
.value = (i64)handle,
|
||||
@@ -266,7 +266,7 @@ fn Resulti64 osFileClose(Resulti64 handle) {
|
||||
fn bool osFileWriteOpenFile(Resulti64 handle, String data) {
|
||||
assert(handle.success == true);
|
||||
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);
|
||||
if (wrote_this_round == -1) return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user