From patchwork Tue Dec 18 15:52:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1015441 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-492745-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="cdf5SBht"; 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 43K2b85GQrz9sCh for ; Wed, 19 Dec 2018 02:52:20 +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=AU3yE8DgJCP9JZKr4jHhaKzli+DrOwVGaAms+ns7LrJ4b8EdEkQoH bIp1VTWgXRQIywzIkWJvfxeyFFsvqIXIOVaTqrUYhpQilkCHkJNXZK+txS3vm94y vwRoEuTCII/7hl2a7ZAO9SafCtsGM6GitYLimHeOCSq3Y2t+OwKXO8= 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=sP70B4a397kwgmnMnE3302v24gs=; b=cdf5SBhtzFBlRae4E1Xy 2E+xoNsf1Ufwa0aRPYK/baLckaRCNumMYQWW8YD+qWunsMYWtssNVRZbsTcGS92A 23vjb8AGsEchXqRFSQE38F+h6k72JJbZCY0IDlL5SpBaib41c9wNfZygnoR75doh aU8TZu5AOWPv/ri0Npa8p90= Received: (qmail 95919 invoked by alias); 18 Dec 2018 15:52:05 -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 95802 invoked by uid 89); 18 Dec 2018 15:52:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=lvalue 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, 18 Dec 2018 15:52:03 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB1928046F; Tue, 18 Dec 2018 15:52:01 +0000 (UTC) Received: from localhost (unknown [10.33.36.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DB6F5D756; Tue, 18 Dec 2018 15:52:01 +0000 (UTC) Date: Tue, 18 Dec 2018 15:52:00 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Micro-optimization to avoid creating temporary path Message-ID: <20181218155200.GA8769@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.10.1 (2018-07-13) Now that path::operator/=(basic_string_view) works directly from the string argument, instead of constructing a temporary path from the string, it's potentially more efficient to do 'path(x) /= s' instead of 'x / s'. This changes the only relevant place in the library. * src/filesystem/std-dir.cc (filesystem::_Dir::advance): Append string to lvalue to avoid creating temporary path. Tested x86_64-linux, committed to trunk. commit e48b1b71c76d12f999d9cf4a12239845281a26e4 Author: Jonathan Wakely Date: Tue Dec 18 15:39:12 2018 +0000 Micro-optimization to avoid creating temporary path Now that path::operator/=(basic_string_view) works directly from the string argument, instead of constructing a temporary path from the string, it's potentially more efficient to do 'path(x) /= s' instead of 'x / s'. This changes the only relevant place in the library. * src/filesystem/std-dir.cc (filesystem::_Dir::advance): Append string to lvalue to avoid creating temporary path. diff --git a/libstdc++-v3/src/filesystem/std-dir.cc b/libstdc++-v3/src/filesystem/std-dir.cc index 038f635a712..216182a2e56 100644 --- a/libstdc++-v3/src/filesystem/std-dir.cc +++ b/libstdc++-v3/src/filesystem/std-dir.cc @@ -61,7 +61,9 @@ struct fs::_Dir : _Dir_base { if (const auto entp = _Dir_base::advance(skip_permission_denied, ec)) { - entry = fs::directory_entry{path / entp->d_name, get_file_type(*entp)}; + auto name = path; + name /= entp->d_name; + entry = fs::directory_entry{name, get_file_type(*entp)}; return true; } else if (!ec)