On Mon, Aug 05, 2013 at 03:59:23PM +0200, jicman wrote:
> 
> Greetings!
> 
> I have this code,
> 
> foreach (...)
> {
> 
>   if (std.string.tolower(fext[0]) == "doc" ||
>     std.string.tolower(fext[0]) == "docx" ||
>     std.string.tolower(fext[0]) == "xls" ||
>     std.string.tolower(fext[0]) == "xlsx" ||
>     std.string.tolower(fext[0]) == "ppt" ||
>     std.string.tolower(fext[0]) == "pptx")
>    continue;
> }
> 
> foreach (...)
> {
>   if (std.string.tolower(fext[0]) == "doc")
>     continue;
>   if (std.string.tolower(fext[0]) == "docx")
>     continue;
>   if (std.string.tolower(fext[0]) == "xls")
>     continue;
>   if (std.string.tolower(fext[0]) == "xlsx")
>     continue;
>   if (std.string.tolower(fext[0]) == "ppt")
>     continue;
>   if (std.string.tolower(fext[0]) == "pptx")
>    continue;
>   ...
>   ...
> }
[...]

It would appear that your bottleneck is not in the continue statements,
but in the repeated calls to std.string.tolower. It's probably better to
write it this way:

        foreach (...)
        {
                auto ext = std.string.tolower(fext[0]);
                if (ext == "doc" || ext == "docx" || ... )
                        continue;
        }

This way you save on the overhead of many identical function calls,
which probably outweights any benefit you get by optimizing continue.


T

-- 
It's amazing how careful choice of punctuation can leave you hanging:

Reply via email to