From patchwork Sun Jan 29 20:33:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 138476 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 07E9D1007D2 for ; Mon, 30 Jan 2012 07:33:35 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1328474016; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=S7+BmHf tSenVagnIYrM0N+Kl8oE=; b=Dinyu4AmGyq9RzzwmR0yC7FIm8yTXGSqxbfh18x UUkgxPr602ruB0jDYz0Ymfx792YJQJbG6sEigyJA56xiNqp1W+EPs3vNfE4/XZ4w ltmokMXoObohqBtgIlSDJhLd4IFChiYLYfD6bJnH1x152JQDmkPNXRowdn/Nn6Mi 88/I= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cXbh250tC4BmlDGs89xKoi0LFixgmd19H3V5F2vDHrFIxIcc8BmH87vxO4YFfN SHAZAH9fWgrt79uIwhXKCOyNa1K9+QrEm3BRz2pBzzLcpBkv+j3tp8ra/6s5wSmh 1o3cCcn2PZttmm7ubfdg9d/1p3rNQYCPYEkxeEvJxqCc4=; Received: (qmail 22292 invoked by alias); 29 Jan 2012 20:33:29 -0000 Received: (qmail 22279 invoked by uid 22791); 29 Jan 2012 20:33:28 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-lpp01m010-f47.google.com (HELO mail-lpp01m010-f47.google.com) (209.85.215.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 29 Jan 2012 20:33:15 +0000 Received: by lahc1 with SMTP id c1so1894275lah.20 for ; Sun, 29 Jan 2012 12:33:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.112.102.37 with SMTP id fl5mr3909244lbb.95.1327869193412; Sun, 29 Jan 2012 12:33:13 -0800 (PST) Received: by 10.152.148.225 with HTTP; Sun, 29 Jan 2012 12:33:13 -0800 (PST) Date: Sun, 29 Jan 2012 22:33:13 +0200 Message-ID: Subject: [Patch, fortran] Reduce size of pointer_info tree From: Janne Blomqvist To: Fortran List , GCC Patches 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 Hi, the attached patch reduces the size of the pointer_info tree used when reading and writing module files by making the module and symbol names pointers rather than arrays. As the strings are already put into heap memory and resized to their correct size during parsing, we have already paid the price of using the heap and we can just point to those parsed strings instead of copying them. Also, a few minor cleanups from my previous patch to heap allocate binding_label. Committed as obvious. 2012-01-29 Janne Blomqvist * module.c (pointer_info): Make true_name and module pointers rather than arrays, order pointers before other fields. (free_pi_tree): free true_name and module as well. (mio_read_string): Rename to read_string. (mio_write_string): Remove. (load_commons): Use read_string. (read_module): Use read_string rather than mio_internal_string. (write_blank_common): Call write_atom directly. (write_symbol): Likewise. diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 4e6c520..c68277b 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -155,13 +155,12 @@ typedef struct pointer_info struct { gfc_symbol *sym; - char true_name[GFC_MAX_SYMBOL_LEN + 1], module[GFC_MAX_SYMBOL_LEN + 1]; + char *true_name, *module, *binding_label; + fixup_t *stfixup; + gfc_symtree *symtree; enum gfc_rsym_state state; int ns, referenced, renamed; module_locus where; - fixup_t *stfixup; - gfc_symtree *symtree; - char* binding_label; } rsym; @@ -229,7 +228,11 @@ free_pi_tree (pointer_info *p) free_pi_tree (p->right); if (iomode == IO_INPUT) - XDELETEVEC (p->u.rsym.binding_label); + { + XDELETEVEC (p->u.rsym.true_name); + XDELETEVEC (p->u.rsym.module); + XDELETEVEC (p->u.rsym.binding_label); + } free (p); } @@ -1442,6 +1445,19 @@ find_enum (const mstring *m) } +/* Read a string. The caller is responsible for freeing. */ + +static char* +read_string (void) +{ + char* p; + require_atom (ATOM_STRING); + p = atom_string; + atom_string = NULL; + return p; +} + + /**************** Module output subroutines ***************************/ /* Output a character to a module file. */ @@ -1816,27 +1832,6 @@ mio_internal_string (char *string) } -/* Read a string. The caller is responsible for freeing. */ - -static char* -mio_read_string (void) -{ - char* p; - require_atom (ATOM_STRING); - p = atom_string; - atom_string = NULL; - return p; -} - - -/* Write a string. */ -static void -mio_write_string (const char* string) -{ - write_atom (ATOM_STRING, string); -} - - typedef enum { AB_ALLOCATABLE, AB_DIMENSION, AB_EXTERNAL, AB_INTRINSIC, AB_OPTIONAL, AB_POINTER, AB_TARGET, AB_DUMMY, AB_RESULT, AB_DATA, @@ -4168,7 +4163,7 @@ load_commons (void) /* Get whether this was a bind(c) common or not. */ mio_integer (&p->is_bind_c); /* Get the binding label. */ - label = mio_read_string (); + label = read_string (); if (strlen (label)) p->binding_label = IDENTIFIER_POINTER (get_identifier (label)); XDELETEVEC (label); @@ -4531,9 +4526,9 @@ read_module (void) info->type = P_SYMBOL; info->u.rsym.state = UNUSED; - mio_internal_string (info->u.rsym.true_name); - mio_internal_string (info->u.rsym.module); - bind_label = mio_read_string (); + info->u.rsym.true_name = read_string (); + info->u.rsym.module = read_string (); + bind_label = read_string (); if (strlen (bind_label)) info->u.rsym.binding_label = bind_label; else @@ -4960,7 +4955,7 @@ write_blank_common (void) mio_integer (&is_bind_c); /* Write out an empty binding label. */ - mio_write_string (""); + write_atom (ATOM_STRING, ""); mio_rparen (); } @@ -5064,7 +5059,7 @@ write_symbol (int n, gfc_symbol *sym) mio_pool_string (&label); } else - mio_write_string (""); + write_atom (ATOM_STRING, ""); mio_pointer_ref (&sym->ns);