shithub: orca

Download patch

ref: 63e699cb0a2681f094deba0c7cc8b809db948bd7
parent: a412b2cddf3ba2e6657417c86bc7ba623277a94f
author: cancel <cancel@cancel.fm>
date: Wed Jan 8 04:15:06 EST 2020

Cleanup

--- a/thirdparty/sdd.c
+++ b/thirdparty/sdd.c
@@ -115,7 +115,34 @@
 sdd *sdd_cpysdd(sdd *restrict s, sdd const *restrict other) {
   return sdd_cpylen(s, (char const *)other, SDD_HDR(other)->len);
 }
+sdd *sdd_cat(sdd *restrict s, char const *restrict other) {
+  return sdd_catlen(s, other, strlen(other));
+}
 SDD_NOINLINE
+sdd *sdd_catlen(sdd *restrict s, char const *restrict other, size_t other_len) {
+  size_t curr_len = SDD_HDR(s)->len;
+  s = sdd_makeroomfor(s, other_len);
+  if (!s)
+    return NULL;
+  memcpy((char *)s + curr_len, other, other_len);
+  ((char *)s)[curr_len + other_len] = '\0';
+  SDD_HDR(s)->len = curr_len + other_len;
+  return s;
+}
+sdd *sdd_catsdd(sdd *restrict s, sdd const *restrict other) {
+  return sdd_catlen(s, (char const *)other, SDD_HDR(other)->len);
+}
+sdd *sdd_catvprintf(sdd *restrict s, char const *fmt, va_list ap) {
+  return sdd_impl_catvprintf(s, fmt, ap);
+}
+sdd *sdd_catprintf(sdd *restrict s, char const *fmt, ...) {
+  va_list ap;
+  va_start(ap, fmt);
+  s = sdd_impl_catvprintf(s, fmt, ap);
+  va_end(ap);
+  return s;
+}
+SDD_NOINLINE
 sdd *sdd_ensurecap(sdd *s, size_t new_cap) {
   sdd_header *hdr = SDD_HDR(s);
   if (new_cap > SDD_CAP_MAX) {
@@ -144,33 +171,6 @@
 size_t sdd_avail(sdd const *s) {
   sdd_header *h = SDD_HDR(s);
   return h->cap - h->len;
-}
-sdd *sdd_cat(sdd *restrict s, char const *restrict other) {
-  return sdd_catlen(s, other, strlen(other));
-}
-SDD_NOINLINE
-sdd *sdd_catlen(sdd *restrict s, char const *restrict other, size_t other_len) {
-  size_t curr_len = SDD_HDR(s)->len;
-  s = sdd_makeroomfor(s, other_len);
-  if (!s)
-    return NULL;
-  memcpy((char *)s + curr_len, other, other_len);
-  ((char *)s)[curr_len + other_len] = '\0';
-  SDD_HDR(s)->len = curr_len + other_len;
-  return s;
-}
-sdd *sdd_catsdd(sdd *restrict s, sdd const *restrict other) {
-  return sdd_catlen(s, (char const *)other, SDD_HDR(other)->len);
-}
-sdd *sdd_catvprintf(sdd *restrict s, char const *fmt, va_list ap) {
-  return sdd_impl_catvprintf(s, fmt, ap);
-}
-sdd *sdd_catprintf(sdd *restrict s, char const *fmt, ...) {
-  va_list ap;
-  va_start(ap, fmt);
-  s = sdd_impl_catvprintf(s, fmt, ap);
-  va_end(ap);
-  return s;
 }
 void sdd_clear(sdd *s) {
   SDD_HDR(s)->len = 0;
--- a/thirdparty/sdd.h
+++ b/thirdparty/sdd.h
@@ -54,21 +54,15 @@
 // ^- Calling with null is allowed.
 
 sdd *sdd_cpy(sdd *restrict s, char const *restrict cstr) SDD_NONNULL() SDD_USED;
-// ^- Set `s` to contain the contents of `cstr`
+// ^- Set `s` to contain the contents of `cstr`. This is really more like
+//    "change into" rather than "copy".
 sdd *sdd_cpylen(sdd *restrict s, char const *restrict cstr, size_t len)
     SDD_NONNULL() SDD_USED;
 sdd *sdd_cpysdd(sdd *restrict s, sdd const *restrict other);
 
-size_t sdd_len(sdd const *s) SDD_NONNULL();
-// ^- Bytes used by string (excl. null term)
-size_t sdd_cap(sdd const *s) SDD_NONNULL();
-// ^- Bytes allocated on heap (excl. null term)
-size_t sdd_avail(sdd const *s) SDD_NONNULL();
-// ^- sdd_cap(s) - sdd_len(s)
-
 sdd *sdd_cat(sdd *restrict s, char const *restrict other)
     SDD_NONNULL() SDD_USED;
-// ^- Appends contents. The two strings must not overlap.
+// ^- Appends contents. The two strings must not overlap in memory.
 sdd *sdd_catlen(sdd *restrict s, char const *restrict other, size_t len)
     SDD_NONNULL() SDD_USED;
 sdd *sdd_catsdd(sdd *restrict s, sdd const *restrict other)
@@ -79,6 +73,13 @@
     SDD_PRINTF(2, 3) SDD_USED;
 // ^- Appends by using printf.
 
+size_t sdd_len(sdd const *s) SDD_NONNULL();
+// ^- Bytes used by string (excluding '\0' terminator)
+size_t sdd_cap(sdd const *s) SDD_NONNULL();
+// ^- Bytes allocated on heap (excluding '\0' terminator)
+size_t sdd_avail(sdd const *s) SDD_NONNULL();
+// ^- sdd_cap(s) - sdd_len(s)
+
 void sdd_clear(sdd *s) SDD_NONNULL();
 // ^- Set len to 0, write '\0' at pos 0. Leaves allocated memory in place.
 void sdd_pokelen(sdd *s, size_t len) SDD_NONNULL();
@@ -92,9 +93,9 @@
 //    only the backing memory allocation.
 sdd *sdd_makeroomfor(sdd *s, size_t add_len) SDD_NONNULL() SDD_USED;
 // ^- Ensure that s has enough allocated space after the valid,
-//    null-terminated characters to hold an additional add_len characters.
-//    It does not adjust the length, only the capacity, if necessary.
-//    Soon after you call sdd_makeroomfor(), you need to call sdd_pokelen(),
+//    null-terminated characters to hold an additional add_len characters. It
+//    does not adjust the length, only the capacity, if necessary. Soon after
+//    you call sdd_makeroomfor(), you probably will want to call sdd_pokelen(),
 //    otherwise you're probably using it incorrectly.
 
 #undef SDD_PRINTF