Fixed non-memory related failing tests
Run tests / Run tests (push) Failing after 9s

This commit is contained in:
2026-05-04 20:42:46 +03:00
parent 396e2c1e52
commit 82abc8fee5
3 changed files with 68 additions and 17 deletions
+47 -14
View File
@@ -40,7 +40,14 @@
/*!
* \brief Rate at which an evstring grows whenever a resize is needed
*/
#define EV_STR_GROWTH_FACTOR 2
#define EV_STR_GROWTH_FACTOR 3 / 2
#endif
#ifndef EV_STR_MIN_CAPACITY
/*!
* \brief Rate at which an evstring grows whenever a resize is needed
*/
#define EV_STR_MIN_CAPACITY 4
#endif
typedef char *evstring;
@@ -120,6 +127,11 @@ evstring_cmp(
const evstring s1,
const evstring s2);
EV_STR_API i32
evstring_view_cmp(
const evstring_view v1,
const evstring_view v2);
EV_STR_API evstring_error_t
evstring_pushChar(
evstring *s,
@@ -213,6 +225,15 @@ TYPEDATA_GEN(evstring,
FREE(Default)
);
DEFINE_EQUAL_FUNCTION(evstring_view, Default)
{
return evstring_view_cmp(*self, *other) == 0;
}
TYPEDATA_GEN(evstring_view,
EQUAL(Default),
);
#if defined(EV_STR_IMPLEMENTATION)
@@ -380,7 +401,8 @@ evstring_grow(
evstring *s)
{
evstr_asserttype(*s);
return evstring_setCapacity(s, META(*s)->capacity * EV_STR_GROWTH_FACTOR);
u64 new_cap = max(EV_STR_MIN_CAPACITY, META(*s)->capacity * EV_STR_GROWTH_FACTOR);
return evstring_setCapacity(s, new_cap);
}
evstring_error_t
@@ -431,6 +453,19 @@ evstring_cmp(
return memcmp(s1, s2, len1);
}
i32
evstring_view_cmp(
const evstring_view v1,
const evstring_view v2)
{
evstr_asserttype(v1.data);
evstr_asserttype(v2.data);
if(v1.len != v2.len) {
return 1;
}
return memcmp(v1.data+v1.offset, v2.data+v2.offset, v1.len);
}
evstring_error_t
evstring_push_impl(
@@ -538,8 +573,6 @@ __evstring_findFirst_impl(
evstring_view text,
evstring_view query)
{
u64 found_progress = 0;
evstring_view result = {
.data = text.data,
.len = 0,
@@ -549,17 +582,17 @@ __evstring_findFirst_impl(
if(query.len == 0)
return result;
for(u64 i = text.offset; i < text.offset + text.len; i++) {
if(text.data[i] == query.data[query.offset + found_progress])
found_progress++;
else
found_progress = 0;
if(found_progress == query.len) {
result.offset = (i+1) - query.len;
result.len = query.len;
break;
}
for(u64 l = text.offset; l <= text.offset + text.len - query.len; l++)
{
evstring_view curr_view = {
.data = text.data,
.len = query.len,
.offset = l
};
if(EV_EQUAL(evstring_view)(&curr_view, &query))
return curr_view;
}
return result;
}