aboutsummaryrefslogtreecommitdiff
path: root/vector.h
Commit message (Collapse)AuthorAgeFilesLines
* fix: double-free of line object in eb_backspace and eb_delete_linedilluti0n2025-05-141-4/+4
| | | | | | | | On eb_backspace, when the upper line was non-null, line_cat followed by line_free, and eb_delete_line only cleared the line_vec. However, commit 2441e78 introduced an additional line_free in eb_delete_line to fix a memory leak, which led to a double-free for that line. This patch resolves that problem.
* refactor: introduce mem.h; wrappers for allocatorsdilluti0n2025-05-101-11/+11
| | | | This patch removes the dependency on raylib when allocating memory.
* fix: Memory Leak in eb_delete_linedilluti0n2025-05-101-3/+3
| | | | | | The function eb_delete_line did not properly free the contents of the entry when deleting an element from eb->line_vec. This patch fixes that issue.
* minor: use #pragma once instead of #ifndef ... on vector.hdilluti0n2025-05-011-4/+1
|
* refactor: introduce lazy loading to each line buffer.dilluti0n2025-04-291-0/+9
| | | | | | | | | | | | | | | | | Each `struct line` now holds a pointer (`origin`) to its corresponding line in the mmap'd file, along with its length (`origin_len`). The `vec` field is no longer allocated for each line during `eb_load_file`. Instead, actual memory allocation and copying into `vec` occurs only when an edit is made or when `line_get_string` is called (since a C string is required). This behavior is handled via the internal inline function `edit_happen`. Also implement `vec_cat_raw` to `line_cat` when lazy `src`. [minor] Remove unused debug messages in editor.c.
* perf: reduce to a single allocation in line_init_from_bufdilluti0n2025-04-291-0/+8
| | | | | | | | Previously, line_init_from_buf called line_init followed by vec_resize, which could result in up to two separate allocations. This patch introduces vec_init_with_capacity, allowing the vector to be initialized with the required capacity in a single step, reducing allocation overhead.
* perf: improve vec_resize to not realloc again and againdilluti0n2025-04-291-1/+7
|
* implement: vec_cleardilluti0n2025-04-281-0/+4
| | | | It just bump size to 0.
* fix: inserting on newline cause segmentatnion faultdilluti0n2025-04-271-0/+1
| | | | | | | | | | This was rely on NULL-initialization of physically allocated vector. When I remove that feature, it immediatly segfalt since logically v->data[index] is not allocated so its not initialized by NULL yet. [minor] add assert on vec_get to avoid this kind of stupid mistake.
* change: remove zero initialization on allocationdilluti0n2025-04-271-14/+24
| | | | | | | instead, this will handle on *_resize for logically allocated segmants. [minor] refactor function vec_grow_to_size to proper name *_resize
* fix: eb_insert to grow line pointer array properlydilluti0n2025-04-271-0/+1
| | | | | | | | | | It was "inserting" the new line to the current eb->cur_row index. Which should just set or push (when inserting to the end of the buffer) to the eb->vec[eb->cur_row]. [minor] add assertion on vec_set. add debug lines on draw loop.
* fix: eb_backspace possable memory leakdilluti0n2025-04-271-1/+4
| | | | | | | | | | | Before deleting curr, it does not freeing it! [minor] optimize vec_delete; if sizeof v is 0, do not call memmove. refactor line_init to clearly indicates both value are initialized to 0. optimize line_cat; if src is empty (['\0']), do not call Vec_char_delete or something.
* fix: vec_cat buffer overrun bugdilluti0n2025-04-271-3/+5
| | | | | | | After grow_to_size called, dest->size already growed. So calling memcpy to dest->data + dest->size causes overrun. There was an anothor problem... it does not update the dest->size either. Both are fixed well.
* fix: vec_cat memcpy sizedilluti0n2025-04-271-1/+2
| | | | multiply sizeof (type)
* refactor: rename vec_grow_size to *_grow_to_size to ambigutydilluti0n2025-04-271-5/+5
| | | | name vec_grow_size has chance to thought growing +dx size for vector.
* implement: line_catdilluti0n2025-04-271-4/+5
| | | | | | [minor] remove 'raylin.h' on makefile fix vector.h to able to compile... (just a minor issues)
* implement: vec_insert_vector and vec_catdilluti0n2025-04-271-0/+18
| | | | It would be clever decision to seperate cat last and insert middle.
* refactor: move debugs to config.h and handle build gracefullydilluti0n2025-04-271-6/+0
| | | | | | | makefile now handle each object and sources seperately to handle header change gracefully. and from now on, #DEBUG should declared inside of config.h
* implement: vec_splitdilluti0n2025-04-271-21/+28
| | | | | [minor] refactor argument i to index for enhance readability
* change: vec_grow_size able to reduce the size toodilluti0n2025-04-241-4/+4
| | | | | Mark eb_newline as TODO because it is not able to insert newline on middle or end of the line.
* change: vector.h now alloc/free its own handledilluti0n2025-04-241-6/+9
|
* implement: eb_backspacedilluti0n2025-04-241-2/+4
|
* implement: vec_deletedilluti0n2025-04-241-58/+74
| | | | minor: tide vector.h macros with proper indents
* fix: vector memory allocation and insert logic; cleanup eb handlingdilluti0n2025-04-211-4/+14
| | | | | | | | - Fixed incorrect `MemAlloc(sizeof(type *))` usage to properly allocate `sizeof(type)` for vector structs. - Corrected `memmove` call in vector insert to account for type size and copy full range. - Added `line_set_cursor()` to set line's cursor position before inserting new lines. - Replaced `line_arr` with `line_vec` in editor buffer for clearer naming. - Improved `DrawText` fallback behavior for NULL lines.
* refactor: line handling and implement basic editor buffer abstractiondilluti0n2025-04-211-4/+13
| | | | | | | | | | | | - Rename vector type VEC -> Vec_char for clarity - Update line.c to use renamed Vec_char API - Add `line_insert` function for character insertion at arbitrary positions - Define Vec_slinep as vector of line pointers in main.c - Introduce `struct ed_buf` as an abstraction for a text buffer - Implement `eb_insert`, `eb_free` and stub `eb_newline`, `eb_backspace` - Update main loop to use `ed_buf` instead of standalone line/lines - Fix vector insertion logic to support gaps and non-contiguous positions - Change optimization level in makefile to -O0 for easier debugging
* implement: vec_insertdilluti0n2025-04-201-1/+18
|
* implement: Unit test for line_appenddilluti0n2025-04-181-0/+3
|
* tabify, gitignoredilluti0n2025-04-181-29/+29
|
* Introduce vector template and migrate line moduledilluti0n2025-04-181-0/+43
* vector.h: Add DEFINE_VECTOR macro for a header-only generic vector template - Implements common operations: init, push, pop, set, get, len, grow * line.[ch]: - Replace fixed char-only vec with VEC (DEFINE_VECTOR(char)) instance - Refactor memory allocation and method calls to use VEC_* macros * makefile: - Remove vec.o from OBJS (vec module is no longer used) * vec.[ch] is now obsolete; new vector types (e.g., line *) can be defined easily using a single DEFINE_VECTOR invocation