more clear variable usage for counting quotes
Graham Knop [Thu, 25 Jan 2018 13:11:44 +0000 (14:11 +0100)]
Use a boolean to track when we need to generate a normal :: separated
package name, rather than an int.  And rename the seen_quote variable to
make it clear that it is a count rather than a boolean.

Name.xs

diff --git a/Name.xs b/Name.xs
index 59a62e8..5f7c06e 100644 (file)
--- a/Name.xs
+++ b/Name.xs
@@ -72,7 +72,8 @@ subname(name, sub)
        STRLEN namelen;
        const char* nameptr = SvPV(name, namelen);
        int utf8flag = SvUTF8(name);
-       int seen_quote = 0, need_subst = 0;
+       int quotes_seen = 0;
+       bool need_subst = FALSE;
     PPCODE:
        if (!SvROK(sub) && SvGMAGICAL(sub))
                mg_get(sub);
@@ -96,21 +97,21 @@ subname(name, sub)
                if (s > nameptr && *s == ':' && s[-1] == ':') {
                        end = s - 1;
                        begin = ++s;
-                       if (seen_quote)
-                               need_subst++;
+                       if (quotes_seen)
+                               need_subst = TRUE;
                }
                else if (s > nameptr && *s != '\0' && s[-1] == '\'') {
                        end = s - 1;
                        begin = s;
-                       if (seen_quote++)
-                               need_subst++;
+                       if (quotes_seen++)
+                               need_subst = TRUE;
                }
        }
        s--;
        if (end) {
                SV* tmp;
                if (need_subst) {
-                       STRLEN length = end - nameptr + seen_quote - (*end == '\'' ? 1 : 0);
+                       STRLEN length = end - nameptr + quotes_seen - (*end == '\'' ? 1 : 0);
                        char* left;
                        int i, j;
                        tmp = newSV(length);