From patchwork Tue Apr 12 18:37:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 90845 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 46617B6F44 for ; Wed, 13 Apr 2011 04:37:51 +1000 (EST) Received: (qmail 2060 invoked by alias); 12 Apr 2011 18:37:49 -0000 Received: (qmail 2052 invoked by uid 22791); 12 Apr 2011 18:37:48 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, SARE_SUB_GETRID, 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; Tue, 12 Apr 2011 18:37:42 +0000 Received: from eggs.gnu.org ([140.186.70.92]:46366) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1Q9iT8-0004Oc-5m for gcc-patches@gnu.org; Tue, 12 Apr 2011 14:37:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q9iT6-0002IE-E2 for gcc-patches@gnu.org; Tue, 12 Apr 2011 14:37:41 -0400 Received: from smtp131.iad.emailsrvr.com ([207.97.245.131]:41172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9iT6-0002I8-BM for gcc-patches@gnu.org; Tue, 12 Apr 2011 14:37:40 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp53.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 587CE58807 for ; Tue, 12 Apr 2011 14:37:39 -0400 (EDT) Received: from dynamic4.wm-web.iad.mlsrvr.com (dynamic4.wm-web.iad1a.rsapps.net [192.168.2.153]) by smtp53.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 400735860B for ; Tue, 12 Apr 2011 14:37:39 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic4.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 286E11D4A310 for ; Tue, 12 Apr 2011 14:37:39 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Tue, 12 Apr 2011 20:37:39 +0200 (CEST) Date: Tue, 12 Apr 2011 20:37:39 +0200 (CEST) Subject: ObjC: get rid of temporary tree list when compiling a method From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1302633459.16216770@192.168.4.58> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 207.97.245.131 X-IsSubscribed: yes 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 This fixes another small inefficiency in the Objective-C compiler. When a method invocation is found, and the parser calls objc_build_method_expr() to compile it, it used to invoke it as in objc_build_message_expr (build_tree_list (rec, args)); this (trivial) patch removes the need to create the temporary tree list, so that the call becomes objc_build_message_expr (rec, args); it's also easier to understand, not just more efficient. The speedup is tiny, as it saves just one allocation per method invocation. It's more about cleaning up the codebase and migrating it from Lisp to C. Ok to commit ? Thanks Index: c-family/c-objc.h =================================================================== --- c-family/c-objc.h (revision 172328) +++ c-family/c-objc.h (working copy) @@ -53,7 +53,7 @@ extern tree objc_is_id (tree); extern void objc_declare_alias (tree, tree); extern void objc_declare_class (tree); extern void objc_declare_protocols (tree, tree); -extern tree objc_build_message_expr (tree); +extern tree objc_build_message_expr (tree, tree); extern tree objc_finish_message_expr (tree, tree, tree, tree*); extern tree objc_build_selector_expr (location_t, tree); extern tree objc_build_protocol_expr (tree); Index: ChangeLog =================================================================== --- ChangeLog (revision 172334) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-12 Nicola Pero + + * c-objc.h (objc_build_message_expr): Updated prototype. + * stub-objc.c (objc_build_message_expr): Likewise. + 2011-04-12 Martin Jambor * c-gimplify.c (c_genericize): Call cgraph_get_create_node instead Index: c-family/stub-objc.c =================================================================== --- c-family/stub-objc.c (revision 172328) +++ c-family/stub-objc.c (working copy) @@ -258,7 +258,7 @@ objc_build_selector_expr (location_t ARG_UNUSED (l } tree -objc_build_message_expr (tree ARG_UNUSED (expr)) +objc_build_message_expr (tree ARG_UNUSED (receiver), tree ARG_UNUSED (args)) { return 0; } Index: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 172328) +++ objc/ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-04-12 Nicola Pero + * objc-act.c (objc_build_message_expr): Accept two arguments + instead of one so that callers can simply pass the arguments + without having to create a temporary chain to hold them. + +2011-04-12 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 Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 172328) +++ objc/objc-act.c (working copy) @@ -5027,14 +5027,13 @@ objc_message_selector (void) (*((*)())_msgSuper)(receiver, selTransTbl[n], ...); */ tree -objc_build_message_expr (tree mess) +objc_build_message_expr (tree receiver, tree message_args) { - tree receiver = TREE_PURPOSE (mess); tree sel_name; #ifdef OBJCPLUS - tree args = TREE_PURPOSE (TREE_VALUE (mess)); + tree args = TREE_PURPOSE (message_args); #else - tree args = TREE_VALUE (mess); + tree args = message_args; #endif tree method_params = NULL_TREE; @@ -5058,7 +5057,7 @@ tree /* Build the parameter list to give to the method. */ if (TREE_CODE (args) == TREE_LIST) #ifdef OBJCPLUS - method_params = chainon (args, TREE_VALUE (TREE_VALUE (mess))); + method_params = chainon (args, TREE_VALUE (message_args)); #else { tree chain = args, prev = NULL_TREE; Index: ChangeLog =================================================================== --- ChangeLog (revision 172328) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-04-12 Nicola Pero + * c-parser.c (c_parser_initelt): Updated call to + objc_build_message_expr. + (c_parser_postfix_expression): Likewise. + +2011-04-12 Nicola Pero + * c-parser.c (c_lex_one_token): Rewritten conditional used when compiling Objective-C to be more efficient. Index: cp/ChangeLog =================================================================== --- cp/ChangeLog (revision 172328) +++ cp/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-12 Nicola Pero + + * parser.c (cp_parser_objc_message_expression): Updated call + to objc_build_message_expr. + 2011-04-12 Martin Jambor * class.c (cp_fold_obj_type_ref): Call cgraph_get_node instead of Index: cp/parser.c =================================================================== --- cp/parser.c (revision 172328) +++ cp/parser.c (working copy) @@ -21289,7 +21289,7 @@ cp_parser_objc_message_expression (cp_parser* pars messageargs = cp_parser_objc_message_args (parser); cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE); - return objc_build_message_expr (build_tree_list (receiver, messageargs)); + return objc_build_message_expr (receiver, messageargs); } /* Parse an objc-message-receiver. Index: c-parser.c =================================================================== --- c-parser.c (revision 172328) +++ c-parser.c (working copy) @@ -3788,7 +3788,7 @@ c_parser_initelt (c_parser *parser, struct obstack c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); mexpr.value - = objc_build_message_expr (build_tree_list (rec, args)); + = objc_build_message_expr (rec, args); mexpr.original_code = ERROR_MARK; mexpr.original_type = NULL; /* Now parse and process the remainder of the @@ -6455,8 +6455,7 @@ c_parser_postfix_expression (c_parser *parser) args = c_parser_objc_message_args (parser); c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); - expr.value = objc_build_message_expr (build_tree_list (receiver, - args)); + expr.value = objc_build_message_expr (receiver, args); break; } /* Else fall through to report error. */