From patchwork Sun Aug 8 20:59:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 61234 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]) by ozlabs.org (Postfix) with SMTP id DDBCDB6EEF for ; Mon, 9 Aug 2010 06:59:36 +1000 (EST) Received: (qmail 29255 invoked by alias); 8 Aug 2010 20:59:34 -0000 Received: (qmail 29246 invoked by uid 22791); 8 Aug 2010 20:59:33 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 08 Aug 2010 20:59:26 +0000 Received: (qmail 5622 invoked from network); 8 Aug 2010 20:59:25 -0000 Received: from unknown (HELO localhost) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 8 Aug 2010 20:59:25 -0000 Date: Sun, 8 Aug 2010 13:59:25 -0700 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH,c++] use VECs in name-lookup.c:is_associated_namespace Message-ID: <20100808205924.GD4130@codesourcery.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-IsSubscribed: yes 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 As $SUBJECT suggests. Sometimes it's a little more work when TREE_LIST users use TREE_PURPOSE instead of TREE_VALUE. ;) The function is slightly longer because we work to recycle the tree vectors. Tested on x86_64-unknown-linux-gnu, libstdc++ and g++ testsuites. OK to commit? -Nathan * name-lookup.c (is_associated_namespace): Convert local variables to be VECs instead of TREE_LISTs. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index c6e31c2..01f29e4 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4659,25 +4659,38 @@ add_function (struct arg_lookup *k, tree fn) bool is_associated_namespace (tree current, tree scope) { - tree seen = NULL_TREE; - tree todo = NULL_TREE; + VEC(tree,gc) *seen = make_tree_vector (); + VEC(tree,gc) *todo = make_tree_vector (); tree t; + bool ret; + while (1) { if (scope == current) - return true; - seen = tree_cons (scope, NULL_TREE, seen); + { + ret = true; + break; + } + VEC_safe_push (tree, gc, seen, scope); for (t = DECL_NAMESPACE_ASSOCIATIONS (scope); t; t = TREE_CHAIN (t)) - if (!purpose_member (TREE_PURPOSE (t), seen)) - todo = tree_cons (TREE_PURPOSE (t), NULL_TREE, todo); - if (todo) + if (!vec_member (TREE_PURPOSE (t), seen)) + VEC_safe_push (tree, gc, todo, TREE_PURPOSE (t)); + if (!VEC_empty (tree, todo)) { - scope = TREE_PURPOSE (todo); - todo = TREE_CHAIN (todo); + scope = VEC_last (tree, todo); + VEC_pop (tree, todo); } else - return false; + { + ret = false; + break; + } } + + release_tree_vector (seen); + release_tree_vector (todo); + + return ret; } /* Add functions of a namespace to the lookup structure.