From patchwork Wed Aug 21 12:57:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1974928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XgOwNtb9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wpmbx0ZD0z1yXf for ; Wed, 21 Aug 2024 22:58:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E70E4386F46D for ; Wed, 21 Aug 2024 12:58:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id EEE47385DDCE for ; Wed, 21 Aug 2024 12:57:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEE47385DDCE Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EEE47385DDCE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724245064; cv=none; b=wbN2Iwspq2QdSHhZCX1lRzu5HO2XGjzKV6YtKwtNJ3JP58ik8kK3H3yt1+PO680guO/4cMwIA3bEELhcWZ1xWhc82SRyKMPi6Y+shER1EVHHVI9db7LsZWztvgJf99IoG9/rJOowQddcL3DFKp28kfzpMY5x4WWMOCf0gd0cZQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724245064; c=relaxed/simple; bh=g8q2gqbHr5TqwrhaSo8qWlLoHiaeN1juvqPU8OavD38=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ir0fjxPZh1x08qD1e+XICDOH/0JxhDcrDVpptFNkJSsbGqtpaL+vfudzvWFKA93K830DY6b8ncAacaPpe0KSPf3cRmEi/6L1cbG3FzfxFvFZO4ZtbbEqrxJ4ZHY005h/lXIZ6dtLMURYwyHiScGbxoI3UAPUxGSpUYouQZYObiY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724245062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n8MnLrEmpHEgZ+8SRNZRcO2cZChUr+ex85piZM8U+yI=; b=XgOwNtb9IfQEIC6yeR842gaLYpo2vO/GiBnIn3QLrANsIDYec2FSIUu2s6bYcY9T6M9mZP CAi6wDabD3VzpRPw837KGvTsbR9E4QInv5/OeH2g2xOrBSxjeAIeh4XY+ZLjTVGz3QTDMe ingtaZTRfQyk9wsgNYJGsl0eu3Ydh8Y= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-M0hMkj1RPVmOLPzesCA4pA-1; Wed, 21 Aug 2024 08:57:41 -0400 X-MC-Unique: M0hMkj1RPVmOLPzesCA4pA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6bf7c81941aso12700356d6.0 for ; Wed, 21 Aug 2024 05:57:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724245060; x=1724849860; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=n8MnLrEmpHEgZ+8SRNZRcO2cZChUr+ex85piZM8U+yI=; b=TzAdxP5PW7v4osAu0xfHhOLJSUtGOtASho4sQM+82//ygkM+fy1rMYHBXePGWVeeAI dMraAelVUzT39nn070iiNuR0nuquxpMyLij/sTdL6DljulwAnj5bfVfHAg4cqI+6GMq9 /TJ3opknEvCr/mCyCgmjW5oFPdeWrs/vC21ivZ/tiWxVJBjiHIoRvaDFLAQuvLgSN87i R5C4aYv8L9jOIlWAwSjFX3+hF36/Iw19eN6rSSW1PTaUG61DXJ5d0P7gvNJUhnbZq8z8 0CH55BYVovPwsc4Ybv35mbcpTGB5eJavWam7jq5tKHNcBT/y+R/Hnoe3lhpQJK4lAyMZ j9hg== X-Gm-Message-State: AOJu0YxmHcNBdd8KN6jqA9DXSvS62G5gyIJRT+ccILJo8loVSeWt4ONo ZA/HECffx57tP2ZJiiQ+dVuCdVmDQ64JEEaBgu8Y3Sd/JaEHmUsTxWx377qmrVDFkAk6DN0gKzQ d/kx6Rk6PD6MMuhcMGfOD/fDEjTM922p9f+UhrtW92CUCCc5BxivkCGmAXefRznq/mSVPiVhmMx TxhUMmbuTtuq/wIPGTA0eIl5rRA3j7A8Z8bFhJ X-Received: by 2002:a05:620a:1909:b0:7a6:6bf5:70c6 with SMTP id af79cd13be357-7a6740d6fdbmr174618985a.7.1724245060444; Wed, 21 Aug 2024 05:57:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEs3gRRG8yzyfRslcOHL1EQlN3t48dWPNp8yFQ84Y+r7nUijh8LwztO9pdt96wLRRsCoJjPAA== X-Received: by 2002:a05:620a:1909:b0:7a6:6bf5:70c6 with SMTP id af79cd13be357-7a6740d6fdbmr174616385a.7.1724245059956; Wed, 21 Aug 2024 05:57:39 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4ff06c496sm620468185a.71.2024.08.21.05.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 05:57:39 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 3/2] libstdc++: Optimize std::projected Date: Wed, 21 Aug 2024 08:57:37 -0400 Message-ID: <20240821125737.3140462-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.0.267.gbb9c16bd4f MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-pc-linux-gnu, does this look OK for trunk? I'm not sure if the current specification of 'projected' strictly speaking allows for this optimization, but it seems like a natural one that should be allowed. -- >8 -- Algorithms that are generalized to take projections usually default the projection to std::identity, which really means no projection at all. In that case, I believe we could shortcut the projection logic to return the indirectly readable type unchanged rather than a wrapped version of it. This should help with compile times especially after P2609R3 which made the indirect invocability concepts more expensive to check when projections are in the picture. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (__detail::__projected): Define partial specialization for a std::identity projection. --- libstdc++-v3/include/bits/iterator_concepts.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index d849ddc32fc..642c709fee0 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -803,6 +803,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __projected_Proj = _Proj; }; }; + + // Optimize the common case of the projection being std::identity. + template + struct __projected<_Iter, identity> + { using __type = _Iter; }; } // namespace __detail /// [projected], projected