summaryrefslogtreecommitdiffstats
path: root/RichString.c
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-12-04 14:44:57 +0100
committerBenBE <BenBE@geshi.org>2020-12-08 20:58:40 +0100
commit157086e750187f6bceeea697d10bf58403c7d5de (patch)
tree82c6512c1a1e88c9ab9f77ca9bf1531da265e331 /RichString.c
parent5506925b346b09f8556ce2c8f83fe3d69dc1c03c (diff)
Split RichString_(append|appendn|write) into wide and ascii
RichString_writeFrom takes a top spot during performance analysis due to the calls to mbstowcs() and iswprint(). Most of the time we know in advance that we are only going to print regular ASCII characters.
Diffstat (limited to 'RichString.c')
-rw-r--r--RichString.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/RichString.c b/RichString.c
index 790c15a9..5dc7ada8 100644
--- a/RichString.c
+++ b/RichString.c
@@ -7,6 +7,7 @@ in the source distribution for its full text.
#include "RichString.h"
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -47,7 +48,7 @@ static void RichString_setLen(RichString* this, int len) {
#ifdef HAVE_LIBNCURSESW
-static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) {
+static inline void RichString_writeFromWide(RichString* this, int attrs, const char* data_c, int from, int len) {
wchar_t data[len + 1];
len = mbstowcs(data, data_c, len);
if (len < 0)
@@ -60,6 +61,14 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
}
}
+static inline void RichString_writeFromAscii(RichString* this, int attrs, const char* data, int from, int len) {
+ int newLen = from + len;
+ RichString_setLen(this, newLen);
+ for (int i = from, j = 0; i < newLen; i++, j++) {
+ this->chptr[i] = (CharType) { .attr = attrs & 0xffffff, .chars = { (isprint(data[j]) ? data[j] : '?') } };
+ }
+}
+
inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
cchar_t* ch = this->chptr + start;
finish = CLAMP(finish, 0, this->chlen - 1);
@@ -82,7 +91,7 @@ int RichString_findChar(RichString* this, char c, int start) {
#else /* HAVE_LIBNCURSESW */
-static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) {
+static inline void RichString_writeFromWide(RichString* this, int attrs, const char* data_c, int from, int len) {
int newLen = from + len;
RichString_setLen(this, newLen);
for (int i = from, j = 0; i < newLen; i++, j++) {
@@ -91,6 +100,10 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char*
this->chptr[newLen] = 0;
}
+static inline void RichString_writeFromAscii(RichString* this, int attrs, const char* data_c, int from, int len) {
+ RichString_writeFromWide(this, attrs, data_c, from, len);
+}
+
void RichString_setAttrn(RichString* this, int attrs, int start, int finish) {
chtype* ch = this->chptr + start;
finish = CLAMP(finish, 0, this->chlen - 1);
@@ -132,14 +145,26 @@ void RichString_setAttr(RichString* this, int attrs) {
RichString_setAttrn(this, attrs, 0, this->chlen - 1);
}
-void RichString_append(RichString* this, int attrs, const char* data) {
- RichString_writeFrom(this, attrs, data, this->chlen, strlen(data));
+void RichString_appendWide(RichString* this, int attrs, const char* data) {
+ RichString_writeFromWide(this, attrs, data, this->chlen, strlen(data));
+}
+
+void RichString_appendnWide(RichString* this, int attrs, const char* data, int len) {
+ RichString_writeFromWide(this, attrs, data, this->chlen, len);
+}
+
+void RichString_writeWide(RichString* this, int attrs, const char* data) {
+ RichString_writeFromWide(this, attrs, data, 0, strlen(data));
+}
+
+void RichString_appendAscii(RichString* this, int attrs, const char* data) {
+ RichString_writeFromAscii(this, attrs, data, this->chlen, strlen(data));
}
-void RichString_appendn(RichString* this, int attrs, const char* data, int len) {
- RichString_writeFrom(this, attrs, data, this->chlen, len);
+void RichString_appendnAscii(RichString* this, int attrs, const char* data, int len) {
+ RichString_writeFromAscii(this, attrs, data, this->chlen, len);
}
-void RichString_write(RichString* this, int attrs, const char* data) {
- RichString_writeFrom(this, attrs, data, 0, strlen(data));
+void RichString_writeAscii(RichString* this, int attrs, const char* data) {
+ RichString_writeFromAscii(this, attrs, data, 0, strlen(data));
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy