From patchwork Tue Dec 18 15:34:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1015439 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-492743-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="ncFVI1/K"; 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 43K2Cx31rFz9s3q for ; Wed, 19 Dec 2018 02:35:41 +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=BPRcp3nQXx5+OJRHpF2KOvsr8qHlJ0uIE4P5lFSanNiQosfRS0cu2 8bGyoCu5iA450zAqwTkBU/TvaM8JxI88hjOI9uVhYqN5VmBtzeIjLoFZKhlgBTb0 slC2jD9Lv0JFSsHYMhcKcUMGpJioZOtcsy+kIF02QAMoK8Y8RPrTQE= 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=VrX98lpaPMSFRioN1Q92+otnJNs=; b=ncFVI1/KrLweBmpAo5Uk 4c33h+1OZ5U3MEqX9WdJ1mf73LSk6o6JD2s17FvpnlWdFNvrlFLihjnL66vtKSs7 1OUMzUtKQwkC7ZSOaI1DMLCYf8CjZzf5hVpWgt24gKPFMYsBOrcYf0fez+5rUMHd imGFxAAHIeGBso/TJr4sffg= Received: (qmail 48907 invoked by alias); 18 Dec 2018 15:35:13 -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 46401 invoked by uid 89); 18 Dec 2018 15:34:31 -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=__x 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:34:30 +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 D8F39A82C; Tue, 18 Dec 2018 15:34:28 +0000 (UTC) Received: from localhost (unknown [10.33.36.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 843CA5D736; Tue, 18 Dec 2018 15:34:28 +0000 (UTC) Date: Tue, 18 Dec 2018 15:34:27 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] LWG 3040: define starts_with/ends_with as proposed Message-ID: <20181218153427.GA7110@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.10.1 (2018-07-13) * include/std/string_view [__cplusplus > 201703L] (basic_string_view::starts_with(basic_string_view)): Implement proposed resolution of LWG 3040 to avoid redundant length check. (basic_string_view::starts_with(_CharT)): Implement proposed resolution of LWG 3040 to check at most one character. (basic_string_view::ends_with(_CharT)): Likewise. Tested powerpc64le-linux, committed to trunk. commit 6567fce9525ef70f9beaf03887213f594545c92e Author: Jonathan Wakely Date: Tue Dec 18 13:53:26 2018 +0000 LWG 3040 define starts_with/ends_with as proposed * include/std/string_view [__cplusplus > 201703L] (basic_string_view::starts_with(basic_string_view)): Implement proposed resolution of LWG 3040 to avoid redundant length check. (basic_string_view::starts_with(_CharT)): Implement proposed resolution of LWG 3040 to check at most one character. (basic_string_view::ends_with(_CharT)): Likewise. diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 28d3fa46718..ac84b24314e 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -389,14 +389,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L constexpr bool starts_with(basic_string_view __x) const noexcept - { - return this->size() >= __x.size() - && this->compare(0, __x.size(), __x) == 0; - } + { return this->substr(0, __x.size()) == __x; } constexpr bool starts_with(_CharT __x) const noexcept - { return this->starts_with(basic_string_view(&__x, 1)); } + { return !this->empty() && traits_type::eq(this->front(), __x); } constexpr bool starts_with(const _CharT* __x) const noexcept @@ -411,7 +408,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr bool ends_with(_CharT __x) const noexcept - { return this->ends_with(basic_string_view(&__x, 1)); } + { return !this->empty() && traits_type::eq(this->back(), __x); } constexpr bool ends_with(const _CharT* __x) const noexcept