File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -836,14 +836,13 @@ defmodule String do
836
836
@ spec ends_with? ( t , t | [ t ] ) :: boolean
837
837
838
838
def ends_with? ( string , suffixes ) when is_list ( suffixes ) do
839
- string_len = String . length ( string )
840
- Enum . any? suffixes ,
841
- fn suffix ->
842
- len = String . length ( suffix )
843
- suffix == String . slice ( string , string_len - len , len )
844
- end
839
+ string_size = size ( string )
840
+ Enum . any? suffixes , fn suffix ->
841
+ suffix_size = size ( suffix )
842
+ ( suffix_size <= string_size ) and suffix == :binary . part ( string , { string_size , - size ( suffix ) } )
843
+ end
845
844
end
846
845
847
- def ends_with? ( string , suffix ) , do: __MODULE__ . ends_with? ( string , [ suffix ] )
846
+ def ends_with? ( string , suffix ) , do: ends_with? ( string , [ suffix ] )
848
847
849
848
end
You can’t perform that action at this time.
0 commit comments