diff options
author | Lloyd Sheng <i@lloydsheng.com> | 2018-06-20 11:39:50 +0800 |
---|---|---|
committer | Lloyd Sheng <i@lloydsheng.com> | 2018-06-20 11:39:50 +0800 |
commit | c087ab1e5608a7e1561dc809dfbf8dc4c12700c6 (patch) | |
tree | 2795565c2379a2df83819d20606d0f72c2946bf0 | |
parent | d0fd03225f5df28b349320e4c7f328baa43522c5 (diff) | |
download | qtlocation-mapboxgl-c087ab1e5608a7e1561dc809dfbf8dc4c12700c6.tar.gz |
Keep the scope of `messageStream` constrained
-rw-r--r-- | src/mbgl/util/stopwatch.hpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mbgl/util/stopwatch.hpp b/src/mbgl/util/stopwatch.hpp index 0782aa742f..0c91342a57 100644 --- a/src/mbgl/util/stopwatch.hpp +++ b/src/mbgl/util/stopwatch.hpp @@ -10,11 +10,14 @@ namespace mbgl { namespace util { #ifdef MBGL_TIMING +// Declare 'watch' as a shared_ptr so it can be captured by value in a lambda function #define MBGL_TIMING_START(watch) std::shared_ptr<util::stopwatch> watch = std::make_unique<util::stopwatch>(Event::Timing); #define MBGL_TIMING_FINISH(watch, message) \ - std::stringstream messageStream; \ - messageStream << message; \ - watch->report(messageStream.str()); + do { \ + std::stringstream messageStream; \ + messageStream << message; \ + watch->report(messageStream.str()); \ + } while (0); #else #define MBGL_TIMING_START(watch) #define MBGL_TIMING_FINISH(watch, message) |