From patchwork Tue Sep 6 10:26:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 113526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BD98AB6F6F for ; Tue, 6 Sep 2011 20:26:34 +1000 (EST) Received: (qmail 10378 invoked by alias); 6 Sep 2011 10:26:30 -0000 Received: (qmail 10362 invoked by uid 22791); 6 Sep 2011 10:26:29 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 06 Sep 2011 10:26:16 +0000 Received: from rtcsinet22.oracle.com (rtcsinet22.oracle.com [66.248.204.30]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p86AQDkm013651 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 6 Sep 2011 10:26:15 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by rtcsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p86AQBLB026500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 6 Sep 2011 10:26:12 GMT Received: from abhmt116.oracle.com (abhmt116.oracle.com [141.146.116.68]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p86AQ6Ke010820; Tue, 6 Sep 2011 05:26:06 -0500 Received: from [192.168.1.4] (/79.53.13.33) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Sep 2011 03:26:06 -0700 Message-ID: <4E65F542.9010400@oracle.com> Date: Tue, 06 Sep 2011 12:26:10 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/50257 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, tested x86_64-linux, committed to mainline. See audit trail for details... Thanks, Paolo. ///////////////////// 2011-09-06 Paolo Carlini PR libstdc++/50257 * include/bits/hashtable_policy.h (_Prime_rehash_policy:: _M_next_bkt): Optimize for small argument. Index: include/bits/hashtable_policy.h =================================================================== --- include/bits/hashtable_policy.h (revision 178574) +++ include/bits/hashtable_policy.h (working copy) @@ -427,8 +427,15 @@ _Prime_rehash_policy:: _M_next_bkt(std::size_t __n) const { - const unsigned long __p = *std::lower_bound(__prime_list, __prime_list - + _S_n_primes, __n); + // Optimize lookups involving the first elements of __prime_list. + // (useful to speed-up, eg, constructors) + static const unsigned char __fastbkt[12] + = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 }; + + const unsigned long __p + = __n <= 11 ? __fastbkt[__n] + : *std::lower_bound(__prime_list + 5, + __prime_list + _S_n_primes, __n); _M_next_resize = static_cast(__builtin_floor(__p * _M_max_load_factor)); return __p;