You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@geode.apache.org by GitBox <gi...@apache.org> on 2021/07/07 22:52:27 UTC

[GitHub] [geode-native] mmartell commented on a change in pull request #830: GEODE-8891: Make static regex a Meyers Singleton in ThinClientRegion

mmartell commented on a change in pull request #830:
URL: https://github.com/apache/geode-native/pull/830#discussion_r665755714



##########
File path: cppcache/src/ThinClientRegion.cpp
##########
@@ -589,7 +595,7 @@ std::shared_ptr<SelectResults> ThinClientRegion::query(
   }
 
   std::string squery;
-  if (std::regex_search(predicate, PREDICATE_IS_FULL_QUERY_REGEX)) {
+  if (std::regex_search(predicate, IsFullQueryRegex::instance())) {

Review comment:
       If initializing a constant something is relatively expensive (i.e., a significant cost relative to its use), I'd prefer to initialize it only once, so I can amortize the cost of initialization.
   
   In this case, I believe mreddington is advocating just declaring it locally inside of functions that use it, and not worry about the cost. Although calling the regex CTOR is likely a small percentage of the total test time, having to recreate a regex that's const seems silly.
   
   If you declare the regex as a const static inside the function that uses it, then it will be initialized only once when the function is first used, thereby solving any cost concern associated with a regex CTOR. Also, C++11 guarantees that dynamic initialization of function-local statics is thread-safe, in case two threads call the function using the local regex at the same time.
   
   So my recommendation is to simply move the original 2 lines of code inside the function that uses it.
   ```
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@geode.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org