From patchwork Fri Nov 8 14:31:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 289850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 19A6F2C00D1 for ; Sat, 9 Nov 2013 01:34:13 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=hrIwZKiyM25OhpVm43+HOTVfDHUEf2ryJtS0Q0fIy6n ays+t6TAvMEJ7rTXf965Zbk7j2QTQ8HqmWQ7iuaFC7/VfRb3sYyEYGsPTIeCSqpK B4pTNmyFbkVplR6RVvLNh0aomndP4Dx/f2aaJKvg7htv0qxNny3DQbKqj1vWC3Nk = 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 :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=OF/N8vZTwMm+UwrzWeXeSkFQUGo=; b=V66vTkPRUAH2gZAsa +jK/ExDysndmQut5LyaVIJZMJipnnlgA4C8DPDMKxNVZ9/N5ssI1bjD57vKm/UyJ 7sgK8Xi+1Uh5483b9I7v7pWhtAYIp9gydMJCVWrtOTN2Y8B01szpcyb/La4NU4xs NNnGhhvEwJgiYk3Lz5VzVaLKWQ= Received: (qmail 16674 invoked by alias); 8 Nov 2013 14:33:34 -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 16630 invoked by uid 89); 8 Nov 2013 14:33:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.1 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPAM_SUBJECT, SPF_PASS autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-la0-f53.google.com Received: from Unknown (HELO mail-la0-f53.google.com) (209.85.215.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 08 Nov 2013 14:31:26 +0000 Received: by mail-la0-f53.google.com with SMTP id eh20so1786143lab.40 for ; Fri, 08 Nov 2013 06:31:17 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.112.205.6 with SMTP id lc6mr1009771lbc.45.1383921077134; Fri, 08 Nov 2013 06:31:17 -0800 (PST) Received: by 10.112.173.195 with HTTP; Fri, 8 Nov 2013 06:31:16 -0800 (PST) Date: Fri, 8 Nov 2013 14:31:16 +0000 Message-ID: Subject: [patch 4/4] std::regex refactoring From: Jonathan Wakely To: "libstdc++" , gcc-patches Cc: Tim Shen , "Stephen M. Webb" As I suggested yesterday on the libstdc++ list, this adds an overload for string and vector iterators to extract a raw pointer and re-use the _Compiler specialization, so that std::regex(".") and std::regex(std::string(".")) and std::regex(std::vector(1, '.')) only instantiate _Compiler once. 2013-11-08 Jonathan Wakely * include/bits/regex_compiler.h (__detail::__compile_nfa): Overload so that std::basic_string and std::vector iterators dispatch to the const C* compiler. Tested x86_64-linux, committed to trunk. commit 76e9d5349657d9eed04d3429dbf7b6527bf03deb Author: Jonathan Wakely Date: Fri Nov 8 13:33:06 2013 +0000 * include/bits/regex_compiler.h (__detail::__compile_nfa): Overload so that std::basic_string and std::vector iterators dispatch to the const C* compiler. diff --git a/libstdc++-v3/include/bits/regex_compiler.h b/libstdc++-v3/include/bits/regex_compiler.h index 406d9a9..741098f 100644 --- a/libstdc++-v3/include/bits/regex_compiler.h +++ b/libstdc++-v3/include/bits/regex_compiler.h @@ -129,8 +129,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _StackT _M_stack; }; + template + struct __has_contiguous_iter : std::false_type { }; + + template + struct __has_contiguous_iter> + : std::true_type + { }; + + template + struct __has_contiguous_iter> + : std::true_type + { }; + + template + struct __is_contiguous_normal_iter : std::false_type { }; + + template + struct + __is_contiguous_normal_iter<__gnu_cxx::__normal_iterator<_Tp, _Cont>> + : __has_contiguous_iter<_Cont>::type + { }; + + template + using __enable_if_contiguous_normal_iter + = typename enable_if< __is_contiguous_normal_iter<_Iter>::value, + std::shared_ptr<_NFA<_TraitsT>> >::type; + + template + using __disable_if_contiguous_normal_iter + = typename enable_if< !__is_contiguous_normal_iter<_Iter>::value, + std::shared_ptr<_NFA<_TraitsT>> >::type; + template - inline std::shared_ptr<_NFA<_TraitsT>> + inline __disable_if_contiguous_normal_iter<_FwdIter, _TraitsT> __compile_nfa(_FwdIter __first, _FwdIter __last, const _TraitsT& __traits, regex_constants::syntax_option_type __flags) { @@ -138,6 +170,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa(); } + template + inline __enable_if_contiguous_normal_iter<_Iter, _TraitsT> + __compile_nfa(_Iter __first, _Iter __last, const _TraitsT& __traits, + regex_constants::syntax_option_type __flags) + { + size_t __len = __last - __first; + const auto* __cfirst = __len ? std::__addressof(*__first) : nullptr; + return __compile_nfa(__cfirst, __cfirst + __len, __traits, __flags); + } + template struct _AnyMatcher {