From patchwork Wed Oct 12 19:13:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 119283 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 D3A17B6F75 for ; Thu, 13 Oct 2011 06:13:34 +1100 (EST) Received: (qmail 9789 invoked by alias); 12 Oct 2011 19:13:31 -0000 Received: (qmail 9781 invoked by uid 22791); 12 Oct 2011 19:13:30 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Oct 2011 19:13:16 +0000 Received: from hpaq12.eem.corp.google.com (hpaq12.eem.corp.google.com [172.25.149.12]) by smtp-out.google.com with ESMTP id p9CJDEun018456; Wed, 12 Oct 2011 12:13:14 -0700 Received: from topo.tor.corp.google.com (topo.tor.corp.google.com [172.29.41.2]) by hpaq12.eem.corp.google.com with ESMTP id p9CJDDxD014240; Wed, 12 Oct 2011 12:13:13 -0700 Received: by topo.tor.corp.google.com (Postfix, from userid 54752) id B0EB71DA1D2; Wed, 12 Oct 2011 15:13:12 -0400 (EDT) To: reply@codereview.appspotmail.com, jason@redhat.com, gcc-patches@gcc.gnu.org Subject: Factor out allocation of sorted_fields (issue5253050) Message-Id: <20111012191312.B0EB71DA1D2@topo.tor.corp.google.com> Date: Wed, 12 Oct 2011 15:13:12 -0400 (EDT) From: dnovillo@google.com (Diego Novillo) X-System-Of-Record: true 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 This moves the allocation of sorted_fields_type elements into a new allocator function. It's not completely necessary in trunk, but in the pph branch we need to allocate this type from pph images, so we need to call it from outside of class.c OK for trunk? Tested on x86_64. Diego. * class.c (sorted_fields_type_new): Factor out of ... (finish_struct_1): ... here. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 2df9177..6185054 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5663,6 +5663,22 @@ determine_key_method (tree type) return; } + +/* Allocate and return an instance of struct sorted_fields_type with + N fields. */ + +static struct sorted_fields_type * +sorted_fields_type_new (int n) +{ + struct sorted_fields_type *sft; + sft = ggc_alloc_sorted_fields_type (sizeof (struct sorted_fields_type) + + n * sizeof (tree)); + sft->len = n; + + return sft; +} + + /* Perform processing required when the definition of T (a class type) is complete. */ @@ -5792,9 +5808,7 @@ finish_struct_1 (tree t) n_fields = count_fields (TYPE_FIELDS (t)); if (n_fields > 7) { - struct sorted_fields_type *field_vec = ggc_alloc_sorted_fields_type - (sizeof (struct sorted_fields_type) + n_fields * sizeof (tree)); - field_vec->len = n_fields; + struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields); add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0); qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp);