aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-13 20:23:48 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-14 01:01:19 +0200
commitd31ab67268d7627e36038c35e0083f3ef2fd60dc (patch)
tree820bfc3c5fef5720d51a919ecec34e0d76342c08
parentb2b3093e0e3cdcacf51e19266b5af710f247afb7 (diff)
downloadxK-d31ab67268d7627e36038c35e0083f3ef2fd60dc.tar.gz
xK-d31ab67268d7627e36038c35e0083f3ef2fd60dc.tar.xz
xK-d31ab67268d7627e36038c35e0083f3ef2fd60dc.zip
xC: mildly optimize relay traffic
-rw-r--r--xC.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/xC.c b/xC.c
index 61be087..7f06083 100644
--- a/xC.c
+++ b/xC.c
@@ -1541,6 +1541,7 @@ struct formatter
struct app_context *ctx; ///< Application context
struct server *s; ///< Server
+ bool clean; ///< Assume ATTR_RESET
struct formatter_item *items; ///< Items
size_t items_len; ///< Items used
size_t items_alloc; ///< Items allocated
@@ -1549,7 +1550,7 @@ struct formatter
static struct formatter
formatter_make (struct app_context *ctx, struct server *s)
{
- struct formatter self = { .ctx = ctx, .s = s };
+ struct formatter self = { .ctx = ctx, .s = s, .clean = true };
self.items = xcalloc (sizeof *self.items, (self.items_alloc = 16));
return self;
}
@@ -3811,7 +3812,7 @@ irc_to_utf8 (const char *text)
// #d inserts a signed integer
// #l inserts a locale-encoded string
//
-// #S inserts a string from the server with unknown encoding
+// #S inserts a string from the server in an unknown encoding
// #m inserts an IRC-formatted string (auto-resets at boundaries)
// #n cuts the nickname from a string and automatically colours it
// #N is like #n but also appends userhost, if present
@@ -3827,6 +3828,17 @@ irc_to_utf8 (const char *text)
static void
formatter_add_item (struct formatter *self, struct formatter_item template_)
{
+ // Auto-resetting tends to create unnecessary items,
+ // which also end up being relayed to frontends, so filter them out.
+ bool reset =
+ template_.type == FORMATTER_ITEM_ATTR &&
+ template_.attribute == ATTR_RESET;
+ if (self->clean && reset)
+ return;
+
+ self->clean = reset ||
+ (self->clean && template_.type == FORMATTER_ITEM_TEXT);
+
if (template_.text)
template_.text = xstrdup (template_.text);