From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22501 invoked by alias); 11 Apr 2011 18:20:16 -0000 Received: (qmail 22299 invoked by uid 22791); 11 Apr 2011 18:20:15 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL,BAYES_40,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 11 Apr 2011 18:20:10 +0000 Received: from eggs.gnu.org ([140.186.70.92]:44943) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1Q9Lib-0006MH-96 for gcc-patches@gnu.org; Mon, 11 Apr 2011 14:20:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q9LiZ-000239-Ma for gcc-patches@gnu.org; Mon, 11 Apr 2011 14:20:09 -0400 Received: from smtp161.iad.emailsrvr.com ([207.97.245.161]:50907) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9LiZ-000235-Io for gcc-patches@gnu.org; Mon, 11 Apr 2011 14:20:07 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp46.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 0855DE8737 for ; Mon, 11 Apr 2011 14:20:07 -0400 (EDT) Received: from dynamic13.wm-web.iad.mlsrvr.com (dynamic13.wm-web.iad1a.rsapps.net [192.168.2.220]) by smtp46.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id E1ED5E874F for ; Mon, 11 Apr 2011 14:20:06 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic13.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id BD7CA3218001 for ; Mon, 11 Apr 2011 14:20:06 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Mon, 11 Apr 2011 20:20:06 +0200 (CEST) Date: Mon, 11 Apr 2011 18:20:00 -0000 Subject: ObjC: do not prepare instance variables for output unless there is an actual error message to print From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 Content-Type: text/plain;charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Type: plain Message-ID: <1302546006.772517913@192.168.4.58> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 207.97.245.161 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg00783.txt.bz2 This is another very small optimization. Whenever the ObjC compiler found an instance variable, it was preparing it for printing it in error messages. Of course, in the typical ObjC compilation run with Foundation and AppKit the compiler will see about 1.5k instance variables, none of which will generate any error message (in most cases), so this patch changes the compiler to only do the work for pretty printing when there is an actual error message to print. The speedup is tiny. Ok to commit ? Thanks Index: ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- ChangeLog (revision 172254) +++ ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-04-11 Nicola Pero + + * objc-act.c (printable_ivar_name): New. + (add_instance_variable): Call printable_ivar_name() when an error + message needs to be printed. Do not prepare the instance variable + for printing unless there is an actual error. + 2011-04-06 Joseph Myers =20 * objc-act.c: Include c-target.h instead of target.h. Index: objc-act.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- objc-act.c (revision 172254) +++ objc-act.c (working copy) @@ -5974,6 +5974,17 @@ flexible_array_type_p (tree type) } #endif =20 +/* Produce a printable version of an ivar name. This is only used + inside add_instance_variable. */ +static const char * +printable_ivar_name (tree field_decl) +{ + if (DECL_NAME (field_decl)) + return identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (field_decl= ))); + else + return _(""); +} + /* Called after parsing each instance variable declaration. Necessary to preserve typedefs and implement public/private... =20 @@ -5984,15 +5995,12 @@ add_instance_variable (tree klass, objc_ivar_visib tree field_decl) { tree field_type =3D TREE_TYPE (field_decl); - const char *ivar_name =3D DECL_NAME (field_decl) - ? identifier_to_locale (IDENTIFIER_POINTER (DECL_= NAME (field_decl))) - : _(""); =20 #ifdef OBJCPLUS if (TREE_CODE (field_type) =3D=3D REFERENCE_TYPE) { error ("illegal reference type specified for instance variable %qs", - ivar_name); + printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass; } @@ -6002,7 +6010,8 @@ add_instance_variable (tree klass, objc_ivar_visib || TYPE_SIZE (field_type) =3D=3D error_mark_node) /* 'type[0]' is allowed, but 'type[]' is not! */ { - error ("instance variable %qs has unknown size", ivar_name); + error ("instance variable %qs has unknown size", + printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass; } @@ -6022,7 +6031,8 @@ add_instance_variable (tree klass, objc_ivar_visib to calculate the offset of the next instance variable. */ if (flexible_array_type_p (field_type)) { - error ("instance variable %qs uses flexible array member", ivar_name= ); + error ("instance variable %qs uses flexible array member", + printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass;=20=20=20=20=20=20 } @@ -6069,7 +6079,7 @@ add_instance_variable (tree klass, objc_ivar_visib error ("type %qE has virtual member functions", type_name); error ("illegal aggregate type %qE specified " "for instance variable %qs", - type_name, ivar_name); + type_name, printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass; }