Remove array alloc, not a good idea

This commit is contained in:
Krzosa Karol
2024-08-10 09:44:44 +02:00
parent f10212f4a0
commit b4bc061b76
2 changed files with 3 additions and 25 deletions

View File

@@ -471,29 +471,6 @@ void BoundedAddError(Array<T> *arr, T item) {
if (arr->len + 1 <= arr->cap) arr->data[arr->len++] = item;
}
template <class T>
T *Alloc(Array<T> *arr, T item) {
TryGrowing(arr);
T *ref = arr->data + arr->len++;
ref[0] = item;
return ref;
}
template <class T>
T *Alloc(Array<T> *arr) {
return Alloc(arr, {});
}
template <class T>
T *AllocMultiple(Array<T> *arr, int64_t count, bool zero_memory = true) {
TryGrowing(arr, count);
T *result = arr->data + arr->len;
arr->len += count;
if (zero_memory)
for (int64_t i = 0; i < count; i += 1) result[i] = {};
return result;
}
template <class T>
void Insert(Array<T> *arr, T item, int64_t index) {
if (index == arr->len) {

View File

@@ -1,7 +1,8 @@
void SaveHistoryBeforeMergeCursor(Buffer *buffer, Array<HistoryEntry> *stack, Array<Caret> &carets) {
if (buffer->no_history) return;
HistoryEntry *entry = Alloc(stack);
entry->carets = TightCopy(GetSystemAllocator(), carets);
HistoryEntry entry = {};
entry.carets = TightCopy(GetSystemAllocator(), carets);
Add(stack, entry);
}
void SaveHistoryBeforeApplyEdits(Buffer *buffer, Array<HistoryEntry> *stack, Array<Edit> &edits) {