From patchwork Tue Apr 10 12:32:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 151535 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 932F0B7000 for ; Tue, 10 Apr 2012 22:32:53 +1000 (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=1334665974; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=V/VSwoR Y6FWiRMhB8Ho0qG+nYOA=; b=Pm26y67BA7vA1j4/YAYsPqXkB+MxxeFM//Rirn2 xP4coiB5pavNkgamnckD4Q4XhoJeYvdF+lrUrl+WNXN6ixI8JrGvTH3veeMiPdqa DaMXJseBM/MRW5kposmhUFLyKGRHTmN01sF8JE3JD/EzboB6ZfFHZNCI1+tZ0+EL QMK4= 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:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=RYFKISPx49oYzLXj0G3i532/qpjYUWPFGl14YGXNTDLXCMp8pMqxvPJIhzyELn s3EGpVjsj78k4mclxNlmy6PHoQ37dLD5UYOY99QlxJf2ebqAjG5lP2uu2Az4Dj7s zinw2MztQicPTSoX+2xx7TQ3GotfNyoq5ZkQZjsq20KVU=; Received: (qmail 3610 invoked by alias); 10 Apr 2012 12:32:43 -0000 Received: (qmail 3504 invoked by uid 22791); 10 Apr 2012 12:32:41 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_NO, TW_CP, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Apr 2012 12:32:26 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id E710F126BE; Tue, 10 Apr 2012 14:32:24 +0200 (CEST) Received: from [192.168.0.109] (xdsl-87-79-196-162.netcologne.de [87.79.196.162]) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA id B9CC611DBC; Tue, 10 Apr 2012 14:32:23 +0200 (CEST) Message-ID: <4F842857.7080105@netcologne.de> Date: Tue, 10 Apr 2012 14:32:23 +0200 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" , gcc-patches Subject: [patch, fortran] Trim spaces on list-directed reads 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, this patch effectively trims the spaces from the string on list-directed reads. This avoids the large overhead on processing these spaces when reading from long lines. I didn't do this for internal units which are arrays because this would need a separate calculation for each record, and would mean a major change to the way the code is structured. The running time for the test case from PR 50673 is reduced from ~8 s to 0.1 s by this patch. Regression-tested. OK for trunk? Thomas 2012-04-09 Thomas Koenig PR libfortran/38199 PR libfortran/50673 * intrinsics/string_intriniscs_inc.c (string_len_trim): Remove prototypes for string_len_trim and move to... * libgfortran.h (string_len_trim): ... here and (string_len_trim_char4): ...here. * io/unit.c: For non-array internal arrays where we do reading, adjust the record length to the last non-blank character. * io/unix.c: Fix typo. Index: intrinsics/string_intrinsics_inc.c =================================================================== --- intrinsics/string_intrinsics_inc.c (Revision 186190) +++ intrinsics/string_intrinsics_inc.c (Arbeitskopie) @@ -44,9 +44,6 @@ extern void concat_string (gfc_charlen_type, CHART gfc_charlen_type, const CHARTYPE *); export_proto(concat_string); -extern gfc_charlen_type string_len_trim (gfc_charlen_type, const CHARTYPE *); -export_proto(string_len_trim); - extern void adjustl (CHARTYPE *, gfc_charlen_type, const CHARTYPE *); export_proto(adjustl); Index: libgfortran.h =================================================================== --- libgfortran.h (Revision 186190) +++ libgfortran.h (Arbeitskopie) @@ -791,6 +791,13 @@ internal_proto(fstrcpy); extern gfc_charlen_type cf_strcpy (char *, gfc_charlen_type, const char *); internal_proto(cf_strcpy); +extern gfc_charlen_type string_len_trim (gfc_charlen_type, const char *); +export_proto(string_len_trim); + +extern gfc_charlen_type string_len_trim_char4 (gfc_charlen_type, + const gfc_char4_t *); +export_proto(string_len_trim_char4); + /* io/intrinsics.c */ extern void flush_all_units (void); Index: io/unit.c =================================================================== --- io/unit.c (Revision 186190) +++ io/unit.c (Arbeitskopie) @@ -397,7 +397,7 @@ get_internal_unit (st_parameter_dt *dtp) __gthread_mutex_lock (&iunit->lock); iunit->recl = dtp->internal_unit_len; - + /* For internal units we set the unit number to -1. Otherwise internal units can be mistaken for a pre-connected unit or some other file I/O unit. */ @@ -415,6 +415,26 @@ get_internal_unit (st_parameter_dt *dtp) start_record *= iunit->recl; } + else + { + /* If we are not processing an array, adjust the unit record length not + to include trailing blanks for list-formatted reads. */ + if (dtp->u.p.mode == READING && dtp->format == NULL) + { + if (dtp->common.unit == 0) + { + dtp->internal_unit_len = + string_len_trim (dtp->internal_unit_len, dtp->internal_unit); + iunit->recl = dtp->internal_unit_len; + } + else + { + dtp->internal_unit_len = + string_len_trim_char4 (dtp->internal_unit_len, dtp->internal_unit); + iunit->recl = dtp->internal_unit_len; + } + } + } /* Set initial values for unit parameters. */ if (dtp->common.unit) Index: io/unix.c =================================================================== --- io/unix.c (Revision 186190) +++ io/unix.c (Arbeitskopie) @@ -736,7 +736,7 @@ mem_alloc_w4 (stream * strm, int * len) } -/* Stream read function for character(kine=1) internal units. */ +/* Stream read function for character(kind=1) internal units. */ static ssize_t mem_read (stream * s, void * buf, ssize_t nbytes)