Skip to content

Commit

Permalink
Speed up StringTools.(starts|ends)With on Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Mar 1, 2023
1 parent ed1622a commit 3172788
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion std/StringTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class StringTools {
public static inline function contains(s:String, value:String):Bool {
#if (js && js_es >= 6)
return (cast s).includes(value);
#else
#else
return s.indexOf(value) != -1;
#end
}
Expand All @@ -234,6 +234,8 @@ class StringTools {
return python.NativeStringTools.startswith(s, start);
#elseif (js && js_es >= 6)
return (cast s).startsWith(start);
#elseif lua
return lua.NativeStringTools.sub(s, 1, start.length).match == start;
#else
return (s.length >= start.length && s.lastIndexOf(start, 0) == 0);
#end
Expand All @@ -259,6 +261,8 @@ class StringTools {
return python.NativeStringTools.endswith(s, end);
#elseif (js && js_es >= 6)
return (cast s).endsWith(end);
#elseif lua
return end == "" || lua.NativeStringTools.sub(s, -end.length).match == end;
#else
var elen = end.length;
var slen = s.length;
Expand Down

0 comments on commit 3172788

Please sign in to comment.