basic/string-util: make ellipsize() inline
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Jun 2018 15:52:07 +0000 (17:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Jun 2018 19:53:25 +0000 (21:53 +0200)
Once the redundant check is removed, it's a very simple wrapper around
ellipsize_mem().

src/basic/string-util.c
src/basic/string-util.h

index 4c7ab3c..882683c 100644 (file)
@@ -607,13 +607,6 @@ char *ellipsize_mem(const char *s, size_t old_length, size_t new_length, unsigne
         return e;
 }
 
-char *ellipsize(const char *s, size_t length, unsigned percent) {
-        if (length == (size_t) -1)
-                return strdup(s);
-
-        return ellipsize_mem(s, strlen(s), length, percent);
-}
-
 char *cellescape(char *buf, size_t len, const char *s) {
         /* Escape and ellipsize s into buffer buf of size len. Only non-control ASCII
          * characters are copied as they are, everything else is escaped. The result
index 25980e7..7e6880b 100644 (file)
@@ -156,7 +156,10 @@ static inline bool _pure_ in_charset(const char *s, const char* charset) {
 bool string_has_cc(const char *p, const char *ok) _pure_;
 
 char *ellipsize_mem(const char *s, size_t old_length_bytes, size_t new_length_columns, unsigned percent);
-char *ellipsize(const char *s, size_t length, unsigned percent);
+static inline char *ellipsize(const char *s, size_t length, unsigned percent) {
+        return ellipsize_mem(s, strlen(s), length, percent);
+}
+
 char *cellescape(char *buf, size_t len, const char *s);
 
 /* This limit is arbitrary, enough to give some idea what the string contains */