From patchwork Tue Nov 13 22:59:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 997414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489958-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Z2Npotl3"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42vjkc1cbFz9rxp for ; Wed, 14 Nov 2018 09:59:52 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=y4Qp/3icU1qokmqmd+URZCI6vjrXghM0kr7KBZVzw2RK5hWn83476 jxFZ/wMsBhcj1H6L2d13P+bSBsdJ7ljx1ym75B0wekKRmFXPwenDZSja+ATP45M2 Iorbavuj5tx5ofwwnriuYXFhwzfI/zqKmh2TpZ0opueyxfFbQnOZJY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=WoGaEGunSqupYVwJedreAjWqxTA=; b=Z2Npotl3SWQXHFyf08PQ Il6qGq/AhKOSJH9Zp65S6QEGCXcjzXdz8r61PjK7o+JU3jq/n6CvnMGDTVCRa5T+ sMvdK+YIpXWAqwq41CuVihILUKPP69EMGPufnbfHuw5ZBnfrfDIje4v8WFBzS/ww EqD3I3H1tEsd/CWJSc4FGSc= Received: (qmail 105210 invoked by alias); 13 Nov 2018 22:59:23 -0000 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 Received: (qmail 105080 invoked by uid 89); 13 Nov 2018 22:59:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Nov 2018 22:59:21 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 420E358E40; Tue, 13 Nov 2018 22:59:20 +0000 (UTC) Received: from localhost (unknown [10.33.36.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE36160851; Tue, 13 Nov 2018 22:59:19 +0000 (UTC) Date: Tue, 13 Nov 2018 22:59:19 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Remove redundant loop in unsynchronized_pool_resource code Message-ID: <20181113225919.GA23837@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.2 (2017-12-15) * src/c++17/memory_resource.cc (bitset::find_first_unset()): Remove unused function. (bitset::get_first_unset()): Remove loop, if there's are unset bits then _M_next_word refers to the first one and there's no need to loop. (_Pool::_Pool(size_t, size_t), _Pool::block_size()): Remove dead code. Tested x86_64-linux, committed to trunk. commit b731b6ff6b9560377356d782ae641876ca410e0d Author: Jonathan Wakely Date: Tue Nov 13 14:43:14 2018 +0000 Remove redundant loop in unsynchronized_pool_resource code * src/c++17/memory_resource.cc (bitset::find_first_unset()): Remove unused function. (bitset::get_first_unset()): Remove loop, if there's are unset bits then _M_next_word refers to the first one and there's no need to loop. (_Pool::_Pool(size_t, size_t), _Pool::block_size()): Remove dead code. diff --git a/libstdc++-v3/src/c++17/memory_resource.cc b/libstdc++-v3/src/c++17/memory_resource.cc index 691a2999de6..b553606f552 100644 --- a/libstdc++-v3/src/c++17/memory_resource.cc +++ b/libstdc++-v3/src/c++17/memory_resource.cc @@ -280,7 +280,7 @@ namespace pmr // Number of blocks size_t size() const noexcept { return _M_size; } - // Number of unset bits + // Number of free blocks (unset bits) size_t free() const noexcept { size_t n = 0; @@ -289,7 +289,7 @@ namespace pmr return n; } - // True if all bits are set + // True if there are no free blocks (all bits are set) bool full() const noexcept { if (_M_next_word >= nwords()) @@ -303,7 +303,7 @@ namespace pmr return false; } - // True if size() != 0 and no bits are set. + // True if size() != 0 and all blocks are free (no bits are set). bool empty() const noexcept { if (nwords() == 0) @@ -333,29 +333,19 @@ namespace pmr return _M_words[wd] & bit; } - size_type find_first_unset() const noexcept - { - for (size_type i = _M_next_word; i < nwords(); ++i) - { - const size_type n = std::__countr_one(_M_words[i]); - if (n < bits_per_word) - return (i * bits_per_word) + n; - } - return size_type(-1); - } - size_type get_first_unset() noexcept { - for (size_type i = _M_next_word; i < nwords(); ++i) + if (_M_next_word < nwords()) { - const size_type n = std::__countr_one(_M_words[i]); + const size_type n = std::__countr_one(_M_words[_M_next_word]); if (n < bits_per_word) { const word bit = word(1) << n; - _M_words[i] |= bit; - if (i == _M_next_word) + _M_words[_M_next_word] |= bit; + const size_t res = (_M_next_word * bits_per_word) + n; + if (n == (bits_per_word - 1)) update_next_word(); - return (i * bits_per_word) + n; + return res; } } return size_type(-1); @@ -605,9 +595,7 @@ namespace pmr : _M_chunks(), _M_block_sz(__block_size), _M_blocks_per_chunk(__blocks_per_chunk) - { - __glibcxx_assert(block_size() == __block_size); - } + { } // Must call release(r) before destruction! ~_Pool() { __glibcxx_assert(_M_chunks.empty()); } @@ -617,11 +605,7 @@ namespace pmr // Size of blocks in this pool size_t block_size() const noexcept -#if POW2_BLKSZ - { return _S_min_block << _M_blksize_mul; } -#else { return _M_block_sz; } -#endif // Allocate a block if the pool is not full, otherwise return null. void* try_allocate() noexcept