comparison mod_firewall/conditions.lib.lua @ 2070:2356114ff505

mod_firewall: Optimize string match operations, string.find is faster than .match since no string is returned
author Kim Alvefur <zash@zash.se>
date Fri, 11 Mar 2016 18:13:53 +0100
parents 7ba6ed553c93
children 4161ff87e5a4
comparison
equal deleted inserted replaced
2069:cf9cd666ba00 2070:2356114ff505
26 local pattern = match:match("<(.*)>"); 26 local pattern = match:match("<(.*)>");
27 if pattern then 27 if pattern then
28 if pattern == "*" then 28 if pattern == "*" then
29 return part; 29 return part;
30 end 30 end
31 if pattern:match("^<.*>$") then 31 if pattern:find("^<.*>$") then
32 pattern = pattern:match("^<(.*)>$"); 32 pattern = pattern:match("^<(.*)>$");
33 else 33 else
34 pattern = pattern:gsub("%p", "%%%0"):gsub("%%(%p)", wildcard_equivs); 34 pattern = pattern:gsub("%p", "%%%0"):gsub("%%(%p)", wildcard_equivs);
35 end 35 end
36 return ("%s:match(%q)"):format(part, "^"..pattern.."$"); 36 return ("%s:match(%q)"):format(part, "^"..pattern.."$");
142 local op = "and"; 142 local op = "and";
143 if day_end_num < day_start_num then 143 if day_end_num < day_start_num then
144 op = "or"; 144 op = "or";
145 end 145 end
146 table.insert(conditions, ("current_day >= %d %s current_day <= %d"):format(day_start_num, op, day_end_num)); 146 table.insert(conditions, ("current_day >= %d %s current_day <= %d"):format(day_start_num, op, day_end_num));
147 elseif day_range:match("%a") then 147 elseif day_range:find("%a") then
148 local day = resolve_day_number(day_range:match("%a+")); 148 local day = resolve_day_number(day_range:match("%a+"));
149 table.insert(conditions, "current_day == "..day); 149 table.insert(conditions, "current_day == "..day);
150 else 150 else
151 error("Unable to parse day/day range: "..day_range); 151 error("Unable to parse day/day range: "..day_range);
152 end 152 end