{"id":2226753,"url":"http://patchwork.ozlabs.org/api/patches/2226753/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhuozlstss.gcc.gcc-TEST.tkaminsk.78.1.11@forge-stage.sourceware.org/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<bmm.hhuozlstss.gcc.gcc-TEST.tkaminsk.78.1.11@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T18:44:09","name":"[v1,11/12] libstdc++: Reuse predicates","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c8b398a4f460d4ff5a1d75ef0ef3c7c78fabb1a9","submitter":{"id":93223,"url":"http://patchwork.ozlabs.org/api/people/93223/?format=json","name":"tkaminsk via Sourceware Forge","email":"forge-bot+tkaminsk@forge-stage.sourceware.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhuozlstss.gcc.gcc-TEST.tkaminsk.78.1.11@forge-stage.sourceware.org/mbox/","series":[{"id":501087,"url":"http://patchwork.ozlabs.org/api/series/501087/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=501087","date":"2026-04-22T18:44:01","name":"remove-predefined-ops","version":1,"mbox":"http://patchwork.ozlabs.org/series/501087/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2226753/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2226753/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org; dmarc=none (p=none dis=none)\n header.from=forge-stage.sourceware.org","sourceware.org;\n spf=pass smtp.mailfrom=forge-stage.sourceware.org","server2.sourceware.org;\n arc=none smtp.remote-ip=38.145.34.39"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g18Dh6yZXz1yHB\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 05:19:48 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 2979346D808B\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 19:19:47 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 72AE840A0652\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:45:35 +0000 (GMT)","from forge-stage.sourceware.org (localhost [IPv6:::1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256)\n (No client certificate requested)\n by forge-stage.sourceware.org (Postfix) with ESMTPS id BAACF4352B\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:45:33 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 2979346D808B","OpenDKIM Filter v2.11.0 sourceware.org 72AE840A0652"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 72AE840A0652","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 72AE840A0652","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776883535; cv=none;\n b=OBBaZirRWLbAPQfxKLF5EClSqQm3sViexOa+VJpv49MbGYRxdu9kfqGYifzETDe+LuWjM64r/KIaaY3ABZBfgykXREuCHqXTLGZ3pWXol/puNIr8B9ESokem0e5+5BltWKnAHg8kYBS+vpttlQ6ELUXkh4X4N5ACd10H1VY0YPk=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776883535; c=relaxed/simple;\n bh=T8pEZXELN3hP436Y1E9CBJd0we/Laptb8u5XfZgzUDk=;\n h=From:Date:Subject:To:Message-ID;\n b=sAPZOWXf744P3nzI3NXYbxbNGgqlIeh30TzQdDc+KMK1GKbS5VmH3zE7CXgE+XpE+4gHEb5wXqPtBPI+uc+d0dEszzBprXr/Y7Pw+wXHpzvfGb2BB/8YmwXcIr3NW6lg7GF3oDYrL480tbXatqSR43iYgzJXx3Fz/naNwvV6AEM=","ARC-Authentication-Results":"i=1; server2.sourceware.org","From":"tkaminsk via Sourceware Forge\n <forge-bot+tkaminsk@forge-stage.sourceware.org>","Date":"Wed, 22 Apr 2026 18:44:09 +0000","Subject":"[PATCH v1 11/12] libstdc++: Reuse predicates","To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>","Message-ID":"\n <bmm.hhuozlstss.gcc.gcc-TEST.tkaminsk.78.1.11@forge-stage.sourceware.org>","X-Mailer":"batrachomyomachia","X-Requested-Reviewer":"fdumont","X-Pull-Request-Organization":"gcc","X-Pull-Request-Repository":"gcc-TEST","X-Pull-Request":"https://forge.sourceware.org/gcc/gcc-TEST/pulls/78","References":"\n <bmm.hhuozlstss.gcc.gcc-TEST.tkaminsk.78.1.0@forge-stage.sourceware.org>","In-Reply-To":"\n <bmm.hhuozlstss.gcc.gcc-TEST.tkaminsk.78.1.0@forge-stage.sourceware.org>","X-Patch-URL":"\n https://forge.sourceware.org/redi/gcc/commit/d287768348d20eabbdca0d436265940ffb9fe81d","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>,\n tkaminsk@gcc.gnu.org","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"From: Jonathan Wakely <jwakely@redhat.com>\n\nlibstdc++-v3/ChangeLog:\n\n\t* include/bits/stl_algobase.h (__search, __is_permutation):\n\tReuse predicate instead of creating a new one each time.\n\t* include/bits/stl_algo.h (__is_permutation): Likewise.\n---\n libstdc++-v3/include/bits/stl_algo.h     | 13 ++++--------\n libstdc++-v3/include/bits/stl_algobase.h | 27 ++++++++++--------------\n 2 files changed, 15 insertions(+), 25 deletions(-)","diff":"diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h\nindex 10f1e1550c4f..5b67d830459d 100644\n--- a/libstdc++-v3/include/bits/stl_algo.h\n+++ b/libstdc++-v3/include/bits/stl_algo.h\n@@ -3531,18 +3531,13 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)\n \n       for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)\n \t{\n-\t  if (__scan != std::__find_if(__first1, __scan,\n-\t\t\t\t       __gnu_cxx::__ops::bind1st(__pred,\n-\t\t\t\t\t\t\t\t *__scan)))\n+\t  auto __scaneq = __gnu_cxx::__ops::bind1st(__pred, *__scan);\n+\t  if (__scan != std::__find_if(__first1, __scan, __scaneq))\n \t    continue; // We've seen this one before.\n \n-\t  auto __matches = std::__count_if(__first2, __last2,\n-\t\t\t\t\t   __gnu_cxx::__ops::bind1st(__pred,\n-\t\t\t\t\t\t\t\t     *__scan));\n+\t  auto __matches = std::__count_if(__first2, __last2, __scaneq);\n \t  if (0 == __matches\n-\t      || std::__count_if(__scan, __last1,\n-\t\t\t\t __gnu_cxx::__ops::bind1st(__pred, *__scan))\n-\t      != __matches)\n+\t\t|| std::__count_if(__scan, __last1, __scaneq) != __matches)\n \t    return false;\n \t}\n       return true;\ndiff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h\nindex 0ac30c65ae30..34a21f118d52 100644\n--- a/libstdc++-v3/include/bits/stl_algobase.h\n+++ b/libstdc++-v3/include/bits/stl_algobase.h\n@@ -2149,21 +2149,21 @@ _GLIBCXX_END_NAMESPACE_ALGO\n       if (__first1 == __last1 || __first2 == __last2)\n \treturn __first1;\n \n+      using __gnu_cxx::__ops::bind2nd;\n+      typedef __decltype(bind2nd(__predicate, *__first2)) _Match1st;\n+      _Match1st __match_first = bind2nd(__predicate, *__first2);\n+\n       // Test for a pattern of length 1.\n       _ForwardIterator2 __p1(__first2);\n       if (++__p1 == __last2)\n-\treturn std::__find_if(__first1, __last1,\n-\t\t\t      __gnu_cxx::__ops::bind2nd(__predicate,\n-\t\t\t\t\t\t\t*__first2));\n+\treturn std::__find_if(__first1, __last1, __match_first);\n \n       // General case.\n       _ForwardIterator1 __current = __first1;\n \n       for (;;)\n \t{\n-\t  __first1 =\n-\t    std::__find_if(__first1, __last1,\n-\t\t\t   __gnu_cxx::__ops::bind2nd(__predicate, *__first2));\n+\t  __first1 = std::__find_if(__first1, __last1, __match_first);\n \n \t  if (__first1 == __last1)\n \t    return __last1;\n@@ -2208,18 +2208,13 @@ _GLIBCXX_END_NAMESPACE_ALGO\n       std::advance(__last2, std::distance(__first1, __last1));\n       for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)\n \t{\n-\t  if (__scan != std::__find_if(__first1, __scan,\n-\t\t\t\t       __gnu_cxx::__ops::bind1st(__pred,\n-\t\t\t\t\t\t\t\t *__scan)))\n+\t  auto __scaneq = __gnu_cxx::__ops::bind1st(__pred, *__scan);\n+\t  if (__scan != std::__find_if(__first1, __scan, __scaneq))\n \t    continue; // We've seen this one before.\n \n-\t  auto __matches\n-\t    = std::__count_if(__first2, __last2,\n-\t\t\t      __gnu_cxx::__ops::bind1st(__pred, *__scan));\n-\t  if (0 == __matches ||\n-\t      std::__count_if(__scan, __last1,\n-\t\t\t      __gnu_cxx::__ops::bind1st(__pred, *__scan))\n-\t      != __matches)\n+\t  auto __matches = std::__count_if(__first2, __last2, __scaneq);\n+\t  if (0 == __matches\n+\t\t|| std::__count_if(__scan, __last1, __scaneq) != __matches)\n \t    return false;\n \t}\n       return true;\n","prefixes":["v1","11/12"]}