On Wednesday, 16. April 2014, 12:03:30, Rolf Eike Beer wrote:
> > Instead of ``"${var}" STREQUAL "VALUE"'', write:
> >
> > IF ( var MATCHES "^VALUE$" )
>
> NOOOOO, please don't! I try hard to kill all those as it requires
> compiling a regular expression for a simple string match. Just change it
> to something that is no valid variable name, i.e. will never get
> expanded:
In principle, you are right. Not too sure, though, whether such a big "NOOOOO"
is warranted. A quick test shows the overhead to be existing, yet not too
severe:
foreach(arg RANGE 10000)
#a) if ( " ${foo}" STREQUAL " ${arg}")
#b) if ( foo MATCHES "^${arg}$")
message("Found it!")
endif()
endforeach()
Method b) has to compile 10.000 regexes, yet the runtime is "only" 30% worse.
And that is even though this example does the opposite of the normal use-case
of the regex, i.e. keeping one fixed regex and matching the variables against
it. I doubt that the overhead is even measurable in the "average" build
system.
#a)
$ time cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zing/scratch/foo
real 0m0.210s
user 0m0.136s
sys 0m0.012s
#b)
$ time cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zing/scratch/foo
real 0m0.278s
user 0m0.220s
sys 0m0.004s
Or are you talking about memory overhead?
>
> if (" ${arg}" STREQUAL " TOTO")
Kudos to you for presenting a (the only?) *safe* prefix.
Johannes
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake