GNU bug report logs - #16544
Optimazation for is_mb_middle

Previous Next

Package: grep;

Reported by: Norihiro Tanaka <noritnk <at> kcn.ne.jp>

Date: Sat, 25 Jan 2014 02:40:02 UTC

Severity: normal

Tags: patch

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Norihiro Tanaka <noritnk <at> kcn.ne.jp>, Jim Meyering <jim <at> meyering.net>
Cc: 16544 <at> debbugs.gnu.org
Subject: bug#16544: Optimazation for is_mb_middle
Date: Tue, 28 Jan 2014 10:37:42 -0800
Thanks for the further patch.  Some comments:

> +      if (!mbsinit (&mbs))
> +        memset (&mbs, 0, sizeof mbs);

Why bother with mbsinit?  Just do the memset, or better yet declare and 
initialize mbs here.

> +      mbclen_guess[i] = mbrlen ((const char *) &i, 1, &mbs);

This assumes a little-endian machine, which is not portable.  Please use 
something like this instead:

  for (i = CHAR_MIN; i <= CHAR_MAX; i++)
    {
       char c = i;
       unsigned char uc = i;
mbstate_t mbs = { 0 };
       mbclen_guess[uc] = mbrlen (&c, 1, &mbs);
    }

Here I'm using a style that avoids casts, as casts in general can be 
dangerous.

A minor question about naming: in what sense is mbclen_guess a guess?  
It doesn't seem to be guessing anything. Perhaps rename it to mbclen_cache?




This bug report was last modified 11 years and 163 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.