Diff

mod_pastebin/mod_pastebin.lua @ 3031:040eaa3844f4

mod_pastebin: Check line length via preconstructed pattern instead of gsub Optimization on the theory that this check scales with the configuration option instead of with the size of the user-supplied message
author Kim Alvefur <zash@zash.se>
date Sun, 20 May 2018 17:55:53 +0200
parent 3030:4a7f08fe793c
child 3032:0f2dd6397569
line wrap: on
line diff
--- a/mod_pastebin/mod_pastebin.lua	Sun May 20 17:54:47 2018 +0200
+++ b/mod_pastebin/mod_pastebin.lua	Sun May 20 17:55:53 2018 +0200
@@ -89,6 +89,8 @@
 	end
 end
 
+local line_count_pattern = string.rep("[^\n]\n", line_threshold):sub(1, -2);
+
 function check_message(data)
 	local origin, stanza = data.origin, data.stanza;
 
@@ -109,8 +111,7 @@
 
 	if ( #body > length_threshold and utf8_length(body) > length_threshold ) or
 		(trigger_string and body:find(trigger_string, 1, true) == 1) or
-		(select(2, body:gsub("\n", "%0")) >= line_threshold)
-	then
+		body:find(line_count_pattern) then
 		if trigger_string and body:sub(1, #trigger_string) == trigger_string then
 			body = body:sub(#trigger_string+1);
 		end