[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
style: minor refactoring
From: |
Akim Demaille |
Subject: |
style: minor refactoring |
Date: |
Mon, 24 Sep 2018 06:48:53 +0200 |
commit 6f344fbe1ba4bd3eaee4492a4caa4f1bee5bd72b
Author: Akim Demaille <address@hidden>
Date: Mon Sep 24 06:31:54 2018 +0200
style: minor refactoring
* data/bison.m4: Formatting changes.
* src/scan-code.l: Avoid loops, prefer standard string functions.
(find_prefix_end): Be const correct.
Avoid useless intermediate variables.
(variant_add): Be const correct.
(parse_ref): Prefer variable definitions to assignments.
diff --git a/data/bison.m4 b/data/bison.m4
index cd810501..adc17543 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -856,9 +856,9 @@ m4_define([b4_percent_define_check_kind],
[b4_error([m4_default([$3], [complain])],
b4_percent_define_get_loc([$1]),
[m4_case([$2],
- [code], [[%%define variable '%s' requires '{...}' values]],
+ [code], [[%%define variable '%s' requires '{...}' values]],
[keyword], [[%%define variable '%s' requires keyword values]],
- [string], [[%%define variable '%s' requires '"..."'
values]])],
+ [string], [[%%define variable '%s' requires '"..."'
values]])],
[$1])])])dnl
])
diff --git a/src/scan-code.l b/src/scan-code.l
index 828ba9ff..f692fc10 100644
--- a/src/scan-code.l
+++ b/src/scan-code.l
@@ -215,10 +215,7 @@ is_dot_or_dash (char ch)
static inline bool
contains_dot_or_dash (const char* p)
{
- for (; *p; ++p)
- if (is_dot_or_dash (*p))
- return true;
- return false;
+ return p[strcspn(p, ".-")] != '\0';
}
/* Defines a variant of a symbolic name resolution. */
@@ -277,26 +274,21 @@ variant_table_free (void)
variant_table_size = variant_count = 0;
}
-static char *
-find_prefix_end (const char *prefix, char *begin, char *end)
+static char const *
+find_prefix_end (char const *prefix, char const *cp, char const *end)
{
- char *ptr = begin;
-
- for (; *prefix && ptr != end; ++prefix, ++ptr)
- if (*prefix != *ptr)
- return 0;
-
- if (*prefix)
- return 0;
+ for (; *prefix && cp != end; ++prefix, ++cp)
+ if (*prefix != *cp)
+ return NULL;
- return ptr;
+ return *prefix ? NULL : cp;
}
static variant *
variant_add (uniqstr id, location id_loc, unsigned symbol_index,
- char *cp, char *cp_end, bool explicit_bracketing)
+ char const *cp, char const *cp_end, bool explicit_bracketing)
{
- char *prefix_end = find_prefix_end (id, cp, cp_end);
+ char const *prefix_end = find_prefix_end (id, cp, cp_end);
if (prefix_end &&
(prefix_end == cp_end ||
(!explicit_bracketing && is_dot_or_dash (*prefix_end))))
@@ -433,31 +425,14 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
}
}
- char *cp_end;
- bool explicit_bracketing;
-
- if ('[' == *cp)
- {
- /* Ignore the brackets. */
- for (cp_end = ++cp; *cp_end != ']'; ++cp_end)
- continue;
+ bool const explicit_bracketing = *cp == '[';
- explicit_bracketing = true;
- }
+ if (explicit_bracketing)
+ ++cp;
else
- {
- /* Take all characters of the name. */
- for (char* p = cp; *p; ++p)
- if (is_dot_or_dash (*p))
- {
- ref_tail_fields = p;
- break;
- }
- for (cp_end = cp; *cp_end; ++cp_end)
- continue;
+ ref_tail_fields = cp + strcspn (cp, ".-");
- explicit_bracketing = false;
- }
+ char const *cp_end = strchr (cp, explicit_bracketing ? ']' : '\0');
/* Add all relevant variants. */
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- style: minor refactoring,
Akim Demaille <=