From patchwork Mon May 17 16:17:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1479625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=FKVYqenC; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FkPS110Vyz9rx6 for ; Tue, 18 May 2021 02:17:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 055B13891C25; Mon, 17 May 2021 16:17:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 055B13891C25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621268271; bh=v+P62xdF+++jIp1ciqsRZAMaR/9HCCaoaYyc7iCxNvY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=FKVYqenCoUaqM4/SWhGBWsjKGYK7YD7+kbXjSaXOdKaRUj1bXyj34cKo9NiDlFRvi IEqBUWp2i4ZZmoKcacbu5eo+eg4lp+9B12Wl0fhzojq1uAXZWHaPVC0cX9AU1yWwJE 8kqDns1NY0Ssugmu2kgimcYfLlHM2S7XMStnXsCs= 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.133.124]) by sourceware.org (Postfix) with ESMTP id 248D5389041A for ; Mon, 17 May 2021 16:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 248D5389041A Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-566-SZOYR2d3PsCT_R1v9AyCkg-1; Mon, 17 May 2021 12:17:46 -0400 X-MC-Unique: SZOYR2d3PsCT_R1v9AyCkg-1 Received: by mail-qt1-f197.google.com with SMTP id 1-20020aed31010000b029019d1c685840so5576770qtg.3 for ; Mon, 17 May 2021 09:17:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=v+P62xdF+++jIp1ciqsRZAMaR/9HCCaoaYyc7iCxNvY=; b=nwhaaFKsPmgBx+unhBSLYUBatw8v+AtVlChiGCmFL718kLfUPS7ohripV3jB/Vv0ZJ xXWF/o4XSlknsBpKVzML9E0TA8ofIc9Fi13DmwPDsQyY4VEsgUsGdFDxEjHG21uYZzCy GIA25ceklEfz/84hqr13736YRFhG3NW4TYsmOS+A8YirOXhWLAMISNkmfBwQ0fatVmLn TdRovA8rv0Y4WyLr9ra8tE2JG4dmJ+hDRFCQHtlCkQZ9dNqHaGL9MIjGR73QLC6jb4dB LKqtTA6ejF6+faFjD+B5VF2aWtanBVyNESr/bwbkcqu7Ep+3zgYk1Ce5R6BXWIGRoLGd Hplw== X-Gm-Message-State: AOAM533K2udhadHWWITQPxbho9Q5C/eoIQ5lULkS9ZjsWrXYueF9WM+s gPbnJG3+/NBJs+I0DfEAXL42pgeQBqO2FRs22LvD59owQLU0KJ1Iccfwzmwc4IdnFNo8EDNs1GC 6vbcdeMqBcbRiRwyrUEGIfdVykh8l9fDeWq5kADGqOs7S/Rp0fiN2uJkT7NVK3yet53U= X-Received: by 2002:a37:317:: with SMTP id 23mr659555qkd.66.1621268265627; Mon, 17 May 2021 09:17:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtMr74TJvXlGDBTeFk2zGXcTfxkMBe0UyJpybu5oxg7K5T5X+AU3CkkpG2LT2hWYroBzMczw== X-Received: by 2002:a37:317:: with SMTP id 23mr659526qkd.66.1621268265335; Mon, 17 May 2021 09:17:45 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id 97sm10661092qte.20.2021.05.17.09.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 09:17:44 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Fix condition for memoizing reverse_view::begin() [PR100621] Date: Mon, 17 May 2021 12:17:43 -0400 Message-Id: <20210517161743.870382-1-ppalka@redhat.com> X-Mailer: git-send-email 2.31.1.621.g97eea85a0a MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.2 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" A range being a random access range is not a sufficient condition for ranges::next(iter, sent) to have constant time complexity; the range must also have a sized sentinel. This adjusts the memoization condition for reverse_view accordingly. Tested on x86_64-pc-linxu-gnu, does this look OK for trunk? Doesn't seem to be worth backporting. libstdc++-v3/ChangeLog: * include/std/ranges (reverse_view::_S_needs_cached_begin): Set to false if the underlying non-common random-access range doesn't have a sized sentinel. --- libstdc++-v3/include/std/ranges | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index bf52074ca05..e93469ca3b4 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -3340,7 +3340,9 @@ namespace views::__adaptor { private: static constexpr bool _S_needs_cached_begin - = !common_range<_Vp> && !random_access_range<_Vp>; + = !common_range<_Vp> && !(random_access_range<_Vp> + && sized_sentinel_for, + iterator_t<_Vp>>); [[no_unique_address]] __detail::__maybe_present_t<_S_needs_cached_begin,