From owner-svn-src-stable@FreeBSD.ORG Fri May 3 17:49:07 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id C9A7C4A4; Fri, 3 May 2013 17:49:07 +0000 (UTC) (envelope-from pluknet@gmail.com) Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [IPv6:2a00:1450:400c:c05::22e]) by mx1.freebsd.org (Postfix) with ESMTP id BDC0F15EE; Fri, 3 May 2013 17:49:06 +0000 (UTC) Received: by mail-wi0-f174.google.com with SMTP id m6so862174wiv.13 for ; Fri, 03 May 2013 10:49:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=4upWFZKPCuvR9X1CDRCNQhw1mSSeii7hf+7Pgz3qfmw=; b=j4qbzSfiKlE/O962C5JXI4C4yS1ApQGd+bjnZu1P6XYDKiYv4jR822f7MMxr6fuceg l5D5k/E5pENZ/XISbZ7mYbOECtQZ2m2YsydSs0pyW0uQrl+XgQ4rnRrI2SEIgSzycbp2 brDAgZPYoFGXE8WA8S+PJWfyhUeOdcPa74AqtwySkwm0672yOwaoC4y0x64Jguo0h1DU elZM9B/mCkIsUX07IRcezl7mVHtKaAQYaGfn2/AvG+Gds0T5Sn2tt7nzOw6BkguS9Rke E4+OB5pJhV+afurm+ecplH3KGgZJR5K2WotJtkDcfq7D+EgIZOeJIxkYJ/X/eqkdQ6Pb u9uA== MIME-Version: 1.0 X-Received: by 10.180.90.203 with SMTP id by11mr14724705wib.10.1367603345899; Fri, 03 May 2013 10:49:05 -0700 (PDT) Sender: pluknet@gmail.com Received: by 10.194.29.199 with HTTP; Fri, 3 May 2013 10:49:05 -0700 (PDT) In-Reply-To: <5183E899.4000503@freebsd.org> References: <201305031552.r43FqiPN024580@svn.freebsd.org> <5183E899.4000503@freebsd.org> Date: Fri, 3 May 2013 21:49:05 +0400 X-Google-Sender-Auth: RjNJkhVqVBILRMLpNHU2wzLB9Hg Message-ID: Subject: Re: svn commit: r250215 - stable/9/lib/libc/locale From: Sergey Kandaurov To: Andrey Chernov Content-Type: text/plain; charset=ISO-8859-1 Cc: svn-src-stable@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, svn-src-stable-9@freebsd.org X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 May 2013 17:49:07 -0000 On 3 May 2013 20:40, Andrey Chernov wrote: > I don't think this change is optimal (cause slowdown) since you add > unneeded strlen() in the loop for known-sized elements plus one strlen() > for tested property, and wctype_l() itself can be called very often, so > we definitely don't need slowdown here. > Since most of elements have equal sizes, your len1 == len2 condition > gains almost nothing for valid calls. Thanks, you are correct. With this change I got 2-6 times slowdown depending on the specified wctype. I will look at how it can be optimized. > > On 03.05.2013 19:52, Sergey Kandaurov wrote: >> Modified: stable/9/lib/libc/locale/wctype.c >> ============================================================================== >> --- stable/9/lib/libc/locale/wctype.c Fri May 3 15:28:31 2013 (r250214) >> +++ stable/9/lib/libc/locale/wctype.c Fri May 3 15:52:43 2013 (r250215) >> @@ -57,35 +57,54 @@ iswctype_l(wint_t wc, wctype_t charclass >> wctype_t >> wctype_l(const char *property, locale_t locale) >> { >> - static const struct { >> - const char *name; >> - wctype_t mask; >> - } props[] = { >> - { "alnum", _CTYPE_A|_CTYPE_D }, >> - { "alpha", _CTYPE_A }, >> - { "blank", _CTYPE_B }, >> - { "cntrl", _CTYPE_C }, >> - { "digit", _CTYPE_D }, >> - { "graph", _CTYPE_G }, >> - { "lower", _CTYPE_L }, >> - { "print", _CTYPE_R }, >> - { "punct", _CTYPE_P }, >> - { "space", _CTYPE_S }, >> - { "upper", _CTYPE_U }, >> - { "xdigit", _CTYPE_X }, >> - { "ideogram", _CTYPE_I }, /* BSD extension */ >> - { "special", _CTYPE_T }, /* BSD extension */ >> - { "phonogram", _CTYPE_Q }, /* BSD extension */ >> - { "rune", 0xFFFFFF00L }, /* BSD extension */ >> - { NULL, 0UL }, /* Default */ >> + const char *propnames = >> + "alnum\0" >> + "alpha\0" >> + "blank\0" >> + "cntrl\0" >> + "digit\0" >> + "graph\0" >> + "lower\0" >> + "print\0" >> + "punct\0" >> + "space\0" >> + "upper\0" >> + "xdigit\0" >> + "ideogram\0" /* BSD extension */ >> + "special\0" /* BSD extension */ >> + "phonogram\0" /* BSD extension */ >> + "rune\0"; /* BSD extension */ >> + static const wctype_t propmasks[] = { >> + _CTYPE_A|_CTYPE_D, >> + _CTYPE_A, >> + _CTYPE_B, >> + _CTYPE_C, >> + _CTYPE_D, >> + _CTYPE_G, >> + _CTYPE_L, >> + _CTYPE_R, >> + _CTYPE_P, >> + _CTYPE_S, >> + _CTYPE_U, >> + _CTYPE_X, >> + _CTYPE_I, >> + _CTYPE_T, >> + _CTYPE_Q, >> + 0xFFFFFF00L >> }; >> - int i; >> + size_t len1, len2; >> + const char *p; >> + const wctype_t *q; >> >> - i = 0; >> - while (props[i].name != NULL && strcmp(props[i].name, property) != 0) >> - i++; >> + len1 = strlen(property); >> + q = propmasks; >> + for (p = propnames; (len2 = strlen(p)) != 0; p += len2 + 1) { >> + if (len1 == len2 && memcmp(property, p, len1) == 0) >> + return (*q); >> + q++; >> + } >> >> - return (props[i].mask); >> + return (0UL); >> } >> >> wctype_t wctype(const char *property) >> > > -- > http://ache.vniz.net/ > bitcoin:13fGiNutKNHcVSsgtGQ7bQ5kgUKgEQHn7N -- wbr, pluknet