regcomp.c: Avoid duplicate work
authorKarl Williamson <khw@cpan.org>
Tue, 25 Dec 2018 19:17:08 +0000 (12:17 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 26 Dec 2018 19:50:37 +0000 (12:50 -0700)
By setting a variable, we can place some subsequent code into an else,
avoiding duplication of work.  (Perhaps the compiler optimizers already
figure this out.)

regcomp.c

index 3c4a590..6f02661 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -10777,16 +10777,18 @@ S_parse_lparen_question_flags(pTHX_ RExC_state_t *pRExC_state)
         RExC_parse++;
         has_use_defaults = TRUE;
         STD_PMMOD_FLAGS_CLEAR(&RExC_flags);
-        set_regex_charset(&RExC_flags, (RExC_uni_semantics)
-                                        ? REGEX_UNICODE_CHARSET
-                                        : REGEX_DEPENDS_CHARSET);
+        cs = (RExC_uni_semantics)
+             ? REGEX_UNICODE_CHARSET
+             : REGEX_DEPENDS_CHARSET;
+        set_regex_charset(&RExC_flags, cs);
     }
-
-    cs = get_regex_charset(RExC_flags);
-    if (cs == REGEX_DEPENDS_CHARSET
-        && (RExC_uni_semantics))
-    {
-        cs = REGEX_UNICODE_CHARSET;
+    else {
+        cs = get_regex_charset(RExC_flags);
+        if (   cs == REGEX_DEPENDS_CHARSET
+            && RExC_uni_semantics)
+        {
+            cs = REGEX_UNICODE_CHARSET;
+        }
     }
 
     while (RExC_parse < RExC_end) {