From e6738b3da5cbd7703cf3fbd905b3fdac19d0ae24 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 27 Apr 2022 10:00:37 +0200 Subject: Internal string container clone optimization. --- include/stc/ccommon.h | 4 +--- include/stc/template.h | 11 ++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index dd048c43..f4961c17 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -87,13 +87,12 @@ #define c_default_cmp(x, y) c_less_cmp(c_default_less, x, y) #define c_default_eq(x, y) (*(x) == *(y)) #define c_memcmp_eq(x, y) (memcmp(x, y, sizeof *(x)) == 0) +#define c_default_hash(p) c_fasthash(p, sizeof *(p)) #define c_default_from(x) (x) #define c_default_toraw(ptr) (*(ptr)) #define c_default_drop(ptr) ((void) (ptr)) -#define c_default_hash(p) c_fasthash(p, sizeof *(p)) - #define c_option(flag) ((i_opt) & (flag)) #define c_is_fwd (1<<0) #define c_no_atomic (1<<1) @@ -107,7 +106,6 @@ typedef const char* crawstr; #define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp)) -#define crawstr_eq(xp, yp) (!strcmp(*(xp), *(yp))) #define crawstr_hash(p) c_strhash(*(p)) #define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) diff --git a/include/stc/template.h b/include/stc/template.h index 659f6a72..a523d07c 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -99,12 +99,14 @@ #if defined i_key_str #define i_key_bind cstr #define i_keyraw crawstr + #define i_keyclone cstr_clone #ifndef i_tag #define i_tag str #endif #elif defined i_key_ssv #define i_key_bind cstr #define i_keyraw csview + #define i_keyclone cstr_clone #define i_keyfrom cstr_from_sv #define i_keyto cstr_sv #define i_eq csview_eq @@ -114,7 +116,6 @@ #elif defined i_key_arcbox #define i_key_bind i_key_arcbox #define i_keyraw c_paste(i_key_arcbox, _value) - // smart pointers have special clone, so override: #define i_keyclone c_paste(i_key_arcbox, _clone) #define _i_no_emplace #endif @@ -148,10 +149,8 @@ #error "no i_key or i_val provided" #elif defined i_keyraw && !defined i_keyfrom #error "if i_keyraw is defined, i_keyfrom (and normally i_keyto) must be defined" -#elif defined i_drop - #error "i_drop not supported. Define i_keydrop/i_valdrop instead." -#elif defined i_from - #error "i_from not supported. Define i_keyfrom/i_valfrom instead." +#elif defined i_from || defined i_drop + #error "i_from / i_drop are not supported. Define i_keyfrom/i_valfrom and-or i_keydrop/i_valdrop instead." #endif #ifndef i_tag @@ -194,9 +193,11 @@ #ifdef i_val_str #define i_val_bind cstr #define i_valraw crawstr + #define i_valclone cstr_clone #elif defined i_val_ssv #define i_val cstr #define i_valraw csview + #define i_valclone cstr_clone #define i_valfrom cstr_from_sv #define i_valto cstr_sv #define i_valdrop cstr_drop -- cgit v1.2.3