summaryrefslogtreecommitdiff
path: root/src/common.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-03-02 12:29:14 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-03-02 12:29:14 +0100
commit74933654160064f9303551a6c012be6b88d5b626 (patch)
tree95191a4335f1a59a407cde9cba010a6c59ebab41 /src/common.cc
parentdf736f5a97b329377e45adb8d734fd58ea9b14ac (diff)
creating and removing buffer
Diffstat (limited to 'src/common.cc')
-rw-r--r--src/common.cc25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/common.cc b/src/common.cc
index 141b079..df8b9aa 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -5,6 +5,7 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
+#include <cstring>
/* typedefs for common types */
@@ -55,8 +56,9 @@ struct Slice {
T* ptr;
usize length;
- Slice() : ptr(nullptr), length(0) {}
+ Slice() : Slice(nullptr, 0) {}
Slice(T* ptr, usize length) : ptr(ptr), length(length) {}
+ Slice(const char* str) : ptr((u8*)str), length(strlen(str)) {}
T* operator[](usize index) {
assert(index < this->length);
@@ -86,14 +88,10 @@ struct Link {
Link* next;
Link* prev;
+ Link() : Link(nullptr, nullptr) {}
Link(Link* next, Link* prev) : next(next), prev(prev) {}
};
-struct List {
- Link head;
- Link tail;
-};
-
static inline void link_after(Link* prev, Link* nlink) {
assert(prev != nullptr);
assert(nlink != nullptr);
@@ -108,4 +106,19 @@ static inline void link_after(Link* prev, Link* nlink) {
next->prev = nlink;
}
+static inline void link_remove(Link* item) {
+ assert(item != nullptr);
+
+ Link* prev = item->prev;
+ Link* next = item->next;
+
+ if(prev != nullptr)
+ prev->next = next;
+
+ if(next != nullptr)
+ next->prev = prev;
+
+ item->prev = item->next = nullptr;
+}
+
#endif