RE: Performance implications of GRegex structure



  char *
  get_leading_digits(const char *str)
  {
     static GRegex *regex = NULL;
     char *result = NULL;

     if (!regex)
         regex = g_regex_new("^\\d+", 0, 0, NULL);

     if (g_regex_match(str, 0))
         result = g_regex_fetch(regex, 0);

     return result;
  }

That code bothers me a fair bit; not because so much because it's
not thread safe, but because it exhibits a pattern that is *inherently*
not thread safe or re-entrant....

Actually if you look at it carefully you realize it is thread safe and
depending on what you call the pattern it too is thread safe.  I think
this is a great way of doing things.  I work in embedded so we are very
sensitive to things like library global constructor creating regex.
That is overhead you pay whether or not you use the function.  That is
also overhead that you pay at launch time which for us is a big deal.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]