[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: the most optimal string "trim" implementation
- From: Gabríel "A." Pétursson <gabrielp@...>
- Date: Fri, 25 Dec 2009 05:42:17 +0000
On Fri, 2009-12-25 at 00:25 -0500, David Manura wrote:
> I contend [1] that the most optimal way to implement a string "trim"
> function is basically this:
>
> function trim(s)
> return s:match'^%s*(.*%S)%s*$' or ''
> end
I can assure you that the following is more optimal:
local string_match = string.match
local function trim(s)
return string_match(s, "^%s*(.*%S)%s*$") or ""
end