Browse Source

MT#55283 slightly improved STR_DUP

This should give slightly better performance due to not having to look
for the terminator byte twice. Not benchmarked. No-op.

Change-Id: I458a06b492393fcf5b186a61b69acabdf63a216e
rfuchs/gh1842
Richard Fuchs 1 year ago
parent
commit
3d35af41fc
1 changed files with 4 additions and 0 deletions
  1. +4
    -0
      lib/str.h

+ 4
- 0
lib/str.h View File

@ -41,7 +41,11 @@ TYPED_GQUEUE(str, str)
#define STR_GS(s) ((str) { (s)->str, (s)->len })
#define STR_LEN(s, len) ((str) { (char *) (s), len })
#define STR_LEN_ASSERT(s, len) ({ assert(sizeof(s) >= len); (str) { (char *) (s), len }; })
#if GLIB_CHECK_VERSION(2,68,0)
#define STR_DUP(s) ({ size_t __l = strlen(s); (str) { g_memdup2(s, __l + 1), __l }; })
#else
#define STR_DUP(s) ((str) { g_strdup(s), strlen(s) })
#endif
#define STR_CONST_BUF(buf) ((str) { (char *) &buf, sizeof(buf) })


Loading…
Cancel
Save