From patchwork Mon Nov 28 20:29:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 128076 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 05DE7B6F81 for ; Tue, 29 Nov 2011 07:29:42 +1100 (EST) Received: (qmail 3223 invoked by alias); 28 Nov 2011 20:29:39 -0000 Received: (qmail 3203 invoked by uid 22791); 28 Nov 2011 20:29:37 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Nov 2011 20:29:19 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id F31A8129C3; Mon, 28 Nov 2011 21:29:17 +0100 (CET) Received: from [192.168.0.106] (xdsl-84-44-154-19.netcologne.de [84.44.154.19]) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA id C663A11D80; Mon, 28 Nov 2011 21:29:16 +0100 (CET) Message-ID: <4ED3EF1C.6080000@netcologne.de> Date: Mon, 28 Nov 2011 21:29:16 +0100 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: fortran@gcc.gnu.org CC: gcc-patches Subject: Re: [Patch, fortran, RFC] PR 40958 Reduce size of module files References: <201111281712.36868.mikael.morin@sfr.fr> In-Reply-To: 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 Hello world, the testing of the test patch I submitted earlier (Thanks Salvatore and Joost!) has shown a performance increase, so here is a formal submission. No test case because this patch is not supposed to change anything, just make module reading a bit more efficient. Regression-tested on x86_64-unknown-linux-gnu. OK for trunk? Thomas 2011-11-28 Thomas Koenig PR fortran/40958 * module.c (prev_module_line): New variable. (prev_module_column): New variable. (prev_character): New variable. (module_char): Update the new variables. (module_unget_char): New function. (parse_string): Use module_unget_char. (parse_integer): Likewise. (parse_name): Likewise. Index: module.c =================================================================== --- module.c (Revision 181745) +++ module.c (Arbeitskopie) @@ -194,6 +194,8 @@ static char module_name[GFC_MAX_SYMBOL_LEN + 1]; static bool specified_nonint, specified_int; static int module_line, module_column, only_flag; +static int prev_module_line, prev_module_column, prev_character; + static enum { IO_INPUT, IO_OUTPUT } iomode; @@ -1036,6 +1038,10 @@ module_char (void) if (c == EOF) bad_module ("Unexpected EOF"); + prev_module_line = module_line; + prev_module_column = module_column; + prev_character = c; + if (c == '\n') { module_line++; @@ -1046,7 +1052,17 @@ module_char (void) return c; } +/* Unget a character while remembering the line and column. Works for + a single character only. */ +static void +module_unget_char (void) +{ + module_line = prev_module_line; + module_column = prev_module_column; + ungetc (prev_character, module_fp); +} + /* Parse a string constant. The delimiter is guaranteed to be a single quote. */ @@ -1106,24 +1122,22 @@ parse_string (void) static void parse_integer (int c) { - module_locus m; - atom_int = c - '0'; for (;;) { - get_module_locus (&m); - c = module_char (); if (!ISDIGIT (c)) - break; + { + module_unget_char (); + break; + } atom_int = 10 * atom_int + c - '0'; if (atom_int > 99999999) bad_module ("Integer overflow"); } - set_module_locus (&m); } @@ -1132,7 +1146,6 @@ parse_integer (int c) static void parse_name (int c) { - module_locus m; char *p; int len; @@ -1141,13 +1154,14 @@ parse_name (int c) *p++ = c; len = 1; - get_module_locus (&m); - for (;;) { c = module_char (); if (!ISALNUM (c) && c != '_' && c != '-') - break; + { + module_unget_char (); + break; + } *p++ = c; if (++len > GFC_MAX_SYMBOL_LEN) @@ -1156,11 +1170,6 @@ parse_name (int c) *p = '\0'; - fseek (module_fp, -1, SEEK_CUR); - module_column = m.column + len - 1; - - if (c == '\n') - module_line--; }