summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2018-02-13 12:58:07 +0100
committerGitHub <noreply@github.com>2018-02-13 12:58:07 +0100
commita2bc308dca885c294d6f63e12b6353115a0f38fe (patch)
tree6ff23f3838b6021c7629404f944bb6dc351c189c
parentc01f6df9573f3a5596bdb4c319faa109567f4221 (diff)
parenta6fcd5432e495aea416ebae28d44111eadf19b82 (diff)
downloadirssi-a2bc308dca885c294d6f63e12b6353115a0f38fe.zip
Merge pull request #846 from ailin-nemui/padding
improve padding performance
-rw-r--r--src/core/special-vars.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/core/special-vars.c b/src/core/special-vars.c
index f254c200..e131b0ed 100644
--- a/src/core/special-vars.c
+++ b/src/core/special-vars.c
@@ -337,11 +337,14 @@ char *get_alignment(const char *text, int align, int flags, char pad)
/* add pad characters */
if (flags & ALIGN_PAD) {
- while (string_width(str->str, policy) < align) {
+ int pad_len = align - string_width(str->str, policy);
+ if (pad_len > 0) {
+ char *pad_full = g_strnfill(pad_len, pad);
if (flags & ALIGN_RIGHT)
- g_string_prepend_c(str, pad);
+ g_string_prepend(str, pad_full);
else
- g_string_append_c(str, pad);
+ g_string_append(str, pad_full);
+ g_free(pad_full);
}
}