From 74933654160064f9303551a6c012be6b88d5b626 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Mon, 2 Mar 2026 12:29:14 +0100 Subject: creating and removing buffer --- src/common.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/common.cc') 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 #include #include +#include /* 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 -- cgit v1.2.3