public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Nicola Pero" <nicola.pero@meta-innovation.com>
To: "gcc-patches@gnu.org" <gcc-patches@gnu.org>
Subject: ObjC: do not prepare instance variables for output unless there is an actual error message to print
Date: Mon, 11 Apr 2011 18:20:00 -0000	[thread overview]
Message-ID: <1302546006.772517913@192.168.4.58> (raw)

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
===================================================================
--- ChangeLog   (revision 172254)
+++ ChangeLog   (working copy)
@@ -1,3 +1,10 @@
+2011-04-11  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       * 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  <joseph@codesourcery.com>
 
        * objc-act.c: Include c-target.h instead of target.h.
Index: objc-act.c
===================================================================
--- objc-act.c  (revision 172254)
+++ objc-act.c  (working copy)
@@ -5974,6 +5974,17 @@ flexible_array_type_p (tree type)
 }
 #endif
 
+/* 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 _("<unnamed>");
+}
+
 /* Called after parsing each instance variable declaration. Necessary to
    preserve typedefs and implement public/private...
 
@@ -5984,15 +5995,12 @@ add_instance_variable (tree klass, objc_ivar_visib
                       tree field_decl)
 {
   tree field_type = TREE_TYPE (field_decl);
-  const char *ivar_name = DECL_NAME (field_decl)
-                         ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (field_decl)))
-                         : _("<unnamed>");
 
 #ifdef OBJCPLUS
   if (TREE_CODE (field_type) == 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) == 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;      
     }
@@ -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;
            }


             reply	other threads:[~2011-04-11 18:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 18:20 Nicola Pero [this message]
2011-04-11 22:09 ` Mike Stump

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1302546006.772517913@192.168.4.58 \
    --to=nicola.pero@meta-innovation.com \
    --cc=gcc-patches@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).