From patchwork Wed Mar 27 08:35:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?T25kxZllaiBCw61sa2E=?= X-Patchwork-Id: 231608 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 5C7C52C009D for ; Wed, 27 Mar 2013 19:41:25 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=N1TozGRJ3/KdpkQc uSVOSxPXwY9pesu84U7Z9wj/XO1B3HJyCT+0ZIxzesrxMYTOCXTsDUcWRYspMJRC SzZ6nVm9vEOrYWbCADE1kxVdWiCHsR+Sh3+ZZDHYME3pAmwGeUlGVI7O0E9Rnfry yjhbDaBYfY1vkaphoQ2+dWUfDxI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=opb+4IND1rh3+7Q909aFf3 qTAmg=; b=YzRea9b9Jh0u0nL6K/xbBWZ/yIVE6vtL848LVAXX2zKlr2LLRoEhJC XPQTR15BQiOTwBeFhF5p2jm809P5nzYP56UxCw/fBBLThufF4e1qm+D+pE7g/X9U 721UOCB1sgqSdZBapyBSnEdhH3XnEKyE3vV0I7sINmIeR/U0UMXBI= Received: (qmail 7528 invoked by alias); 27 Mar 2013 08:40:59 -0000 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 Received: (qmail 7033 invoked by uid 89); 27 Mar 2013 08:40:51 -0000 X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_NEUTRAL autolearn=no version=3.3.1 Received: from popelka.ms.mff.cuni.cz (HELO popelka.ms.mff.cuni.cz) (195.113.20.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 27 Mar 2013 08:40:46 +0000 Received: from domone.kolej.mff.cuni.cz (popelka.ms.mff.cuni.cz [195.113.20.131]) by popelka.ms.mff.cuni.cz (Postfix) with ESMTPS id D32E3521FD for ; Wed, 27 Mar 2013 09:40:41 +0100 (CET) Received: by domone.kolej.mff.cuni.cz (Postfix, from userid 1000) id A9B516045D; Wed, 27 Mar 2013 09:35:57 +0100 (CET) Date: Wed, 27 Mar 2013 09:35:57 +0100 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: gcc-patches@gcc.gnu.org Subject: [Patch, fortran] optimize string comparison Message-ID: <20130327083557.GB6374@domone.kolej.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Hi, as I looked to compare_string I discovered that it could be optimized. This speeds up case when strings are equal but we must check padding where checking it byte by byte is suboptimal. Ondra 2013-03-27 Ondřej Bílka * libgfortran/intrinsics/string_intrinsics_inc.c (compare_string): Optimize. diff --git a/libgfortran/intrinsics/string_intrinsics_inc.c b/libgfortran/intrinsics/string_intrinsics_inc.c index a1f86b5..9eb0613 100644 --- a/libgfortran/intrinsics/string_intrinsics_inc.c +++ b/libgfortran/intrinsics/string_intrinsics_inc.c @@ -107,16 +107,15 @@ compare_string (gfc_charlen_type len1, const CHARTYPE *s1, res = 1; } - while (len--) + s = memchr (s, ' ', len); + if (!s) + return 0; + if (*s != ' ') { - if (*s != ' ') - { - if (*s > ' ') - return res; - else - return -res; - } - s++; + if (*s > ' ') + return res; + else + return -res; } return 0;