Paolo Bonzini wrote:
> On 09/15/2011 02:21 PM, Jim Meyering wrote:
>>> > As an additional cleanup, you can make using_utf8() return always
>>> > false if !MBS_SUPPORT.
>> using_utf8 does that already:
>>
>> static inline int
>> using_utf8 (void)
>> {
>> static int utf8 = -1;
>> if (utf8 == -1)
>> {
>> #if defined HAVE_LANGINFO_CODESET&& defined MBS_SUPPORT
>> utf8 = (STREQ (nl_langinfo (CODESET), "UTF-8"));
>> #else
>> utf8 = 0;
>> #endif
>> }
>>
>> return utf8;
>> }
>
> Then I missed the conversion to if() in you patch series, or equivalently to
The patch series did not convert the above #if...MBS_SUPPORT to if (...).
> static int utf8 = MBS_SUPPORT ? -1 : 0;
That is not needed.
When !MBS_SUPPORT, the function always returns 0.
>>> > This lets you clean up dfa_optimize further.
>
> This still stands. :)
Here's one small way to simplify it:
(due to indentation change, that's hard to read.
I've appended diff -b output)
>From c1742b15f0eb824b332a2aa6e03fbeb0774a460f Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Thu, 15 Sep 2011 14:39:44 +0200
Subject: [PATCH] maint: dfa: simplify dfaoptimize
* src/dfa.c (dfaoptimize): Simplify.
---
src/dfa.c | 37 +++++++++++++++++--------------------
1 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/src/dfa.c b/src/dfa.c
index 35695f9..45c7d71 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3418,30 +3418,27 @@ dfainit (struct dfa *d)
static void
dfaoptimize (struct dfa *d)
{
- if (MBS_SUPPORT)
- {
- unsigned int i;
- if (!using_utf8())
- return;
+ if (!MBS_SUPPORT || !using_utf8())
+ return;
- for (i = 0; i < d->tindex; ++i)
+ unsigned int i;
+ for (i = 0; i < d->tindex; ++i)
+ {
+ switch(d->tokens[i])
{
- switch(d->tokens[i])
- {
- case ANYCHAR:
- /* Lowered. */
- abort ();
- case MBCSET:
- /* Requires multi-byte algorithm. */
- return;
- default:
- break;
- }
+ case ANYCHAR:
+ /* Lowered. */
+ abort ();
+ case MBCSET:
+ /* Requires multi-byte algorithm. */
+ return;
+ default:
+ break;
}
-
- free_mbdata (d);
- d->mb_cur_max = 1;
}
+
+ free_mbdata (d);
+ d->mb_cur_max = 1;
}
/* Parse and analyze a single string of the given length. */
--
1.7.7.rc0.362.g5a14
diff --git a/src/dfa.c b/src/dfa.c
index 35695f9..45c7d71 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -3418,12 +3418,10 @@ dfainit (struct dfa *d)
static void
dfaoptimize (struct dfa *d)
{
- if (MBS_SUPPORT)
- {
- unsigned int i;
- if (!using_utf8())
+ if (!MBS_SUPPORT || !using_utf8())
return;
+ unsigned int i;
for (i = 0; i < d->tindex; ++i)
{
switch(d->tokens[i])
@@ -3441,7 +3439,6 @@ dfaoptimize (struct dfa *d)
free_mbdata (d);
d->mb_cur_max = 1;
- }
}
/* Parse and analyze a single string of the given length. */