This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: Speed up new parser


This sequeezes a bit more performance (a few percent) out of the new
parser by inlining the little functions that showed up a lot in the
profile.

Tested on i686-pc-linux-gnu, applied on the mainline.

-- 
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2003-01-02  Mark Mitchell  <mark@codesourcery.com>

	* parser.c (cp_lexer_next_token_is): Declare it inline.
	(cp_lexer_set_source_position_from_token): Likewise.
	(cp_lexer_debugging_p): Likewise.
	(cp_parser_parsing_tentatively): Likewise.
	(cp_parser_nested_name_specifier_opt): Reduce the number of calls
	to the cp_lexer_peek_token.

Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.13
diff -c -p -r1.13 parser.c
*** parser.c	2 Jan 2003 18:12:28 -0000	1.13
--- parser.c	2 Jan 2003 19:05:07 -0000
*************** static cp_token *cp_lexer_peek_token
*** 233,239 ****
    PARAMS ((cp_lexer *));
  static cp_token *cp_lexer_peek_nth_token
    PARAMS ((cp_lexer *, size_t));
! static bool cp_lexer_next_token_is
    PARAMS ((cp_lexer *, enum cpp_ttype));
  static bool cp_lexer_next_token_is_not
    PARAMS ((cp_lexer *, enum cpp_ttype));
--- 233,239 ----
    PARAMS ((cp_lexer *));
  static cp_token *cp_lexer_peek_nth_token
    PARAMS ((cp_lexer *, size_t));
! static inline bool cp_lexer_next_token_is
    PARAMS ((cp_lexer *, enum cpp_ttype));
  static bool cp_lexer_next_token_is_not
    PARAMS ((cp_lexer *, enum cpp_ttype));
*************** static void cp_lexer_commit_tokens
*** 251,261 ****
    PARAMS ((cp_lexer *));
  static void cp_lexer_rollback_tokens
    PARAMS ((cp_lexer *));
! static void cp_lexer_set_source_position_from_token 
    PARAMS ((cp_lexer *, const cp_token *));
  static void cp_lexer_print_token
    PARAMS ((FILE *, cp_token *));
! static bool cp_lexer_debugging_p 
    PARAMS ((cp_lexer *));
  static void cp_lexer_start_debugging
    PARAMS ((cp_lexer *)) ATTRIBUTE_UNUSED;
--- 251,261 ----
    PARAMS ((cp_lexer *));
  static void cp_lexer_rollback_tokens
    PARAMS ((cp_lexer *));
! static inline void cp_lexer_set_source_position_from_token 
    PARAMS ((cp_lexer *, const cp_token *));
  static void cp_lexer_print_token
    PARAMS ((FILE *, cp_token *));
! static inline bool cp_lexer_debugging_p 
    PARAMS ((cp_lexer *));
  static void cp_lexer_start_debugging
    PARAMS ((cp_lexer *)) ATTRIBUTE_UNUSED;
*************** cp_lexer_new_from_tokens (cp_token_cache
*** 368,386 ****
    return lexer;
  }
  
! /* Non-zero if we are presently saving tokens.  */
  
! static int
! cp_lexer_saving_tokens (lexer)
!      const cp_lexer *lexer;
  {
!   return VARRAY_ACTIVE_SIZE (lexer->saved_tokens) != 0;
  }
  
  /* TOKEN points into the circular token buffer.  Return a pointer to
     the next token in the buffer.  */
  
! static cp_token *
  cp_lexer_next_token (lexer, token)
       cp_lexer *lexer;
       cp_token *token;
--- 368,404 ----
    return lexer;
  }
  
! /* Returns non-zero if debugging information should be output.  */
  
! static inline bool
! cp_lexer_debugging_p (cp_lexer *lexer)
  {
!   return lexer->debugging_p;
! }
! 
! /* Set the current source position from the information stored in
!    TOKEN.  */
! 
! static inline void
! cp_lexer_set_source_position_from_token (lexer, token)
!      cp_lexer *lexer ATTRIBUTE_UNUSED;
!      const cp_token *token;
! {
!   /* Ideally, the source position information would not be a global
!      variable, but it is.  */
! 
!   /* Update the line number.  */
!   if (token->type != CPP_EOF)
!     {
!       lineno = token->line_number;
!       input_filename = token->file_name;
!     }
  }
  
  /* TOKEN points into the circular token buffer.  Return a pointer to
     the next token in the buffer.  */
  
! static inline cp_token *
  cp_lexer_next_token (lexer, token)
       cp_lexer *lexer;
       cp_token *token;
*************** cp_lexer_next_token (lexer, token)
*** 391,396 ****
--- 409,423 ----
    return token;
  }
  
+ /* Non-zero if we are presently saving tokens.  */
+ 
+ static int
+ cp_lexer_saving_tokens (lexer)
+      const cp_lexer *lexer;
+ {
+   return VARRAY_ACTIVE_SIZE (lexer->saved_tokens) != 0;
+ }
+ 
  /* Return a pointer to the token that is N tokens beyond TOKEN in the
     buffer.  */
  
*************** cp_lexer_rollback_tokens (lexer)
*** 916,940 ****
    VARRAY_POP (lexer->saved_tokens);
  }
  
- /* Set the current source position from the information stored in
-    TOKEN.  */
- 
- static void
- cp_lexer_set_source_position_from_token (lexer, token)
-      cp_lexer *lexer ATTRIBUTE_UNUSED;
-      const cp_token *token;
- {
-   /* Ideally, the source position information would not be a global
-      variable, but it is.  */
- 
-   /* Update the line number.  */
-   if (token->type != CPP_EOF)
-     {
-       lineno = token->line_number;
-       input_filename = token->file_name;
-     }
- }
- 
  /* Print a representation of the TOKEN on the STREAM.  */
  
  static void
--- 943,948 ----
*************** cp_lexer_print_token (stream, token)
*** 1007,1021 ****
      fprintf (stream, " %s", IDENTIFIER_POINTER (token->value));
  }
  
- /* Returns non-zero if debugging information should be output.  */
- 
- static bool
- cp_lexer_debugging_p (lexer)
-      cp_lexer *lexer;
- {
-   return lexer->debugging_p;
- }
- 
  /* Start emitting debugging information.  */
  
  static void
--- 1015,1020 ----
*************** static void cp_parser_abort_tentative_pa
*** 1747,1753 ****
    PARAMS ((cp_parser *));
  static bool cp_parser_parse_definitely
    PARAMS ((cp_parser *));
! static bool cp_parser_parsing_tentatively
    PARAMS ((cp_parser *));
  static bool cp_parser_committed_to_tentative_parse
    PARAMS ((cp_parser *));
--- 1746,1752 ----
    PARAMS ((cp_parser *));
  static bool cp_parser_parse_definitely
    PARAMS ((cp_parser *));
! static inline bool cp_parser_parsing_tentatively
    PARAMS ((cp_parser *));
  static bool cp_parser_committed_to_tentative_parse
    PARAMS ((cp_parser *));
*************** static void cp_parser_perform_deferred_a
*** 1800,1805 ****
--- 1799,1813 ----
  static tree cp_parser_scope_through_which_access_occurs
    (tree, tree, tree);
  
+ /* Returns non-zero if we are parsing tentatively.  */
+ 
+ static inline bool
+ cp_parser_parsing_tentatively (parser)
+      cp_parser *parser;
+ {
+   return parser->context->next != NULL;
+ }
+ 
  /* Returns non-zero if TOKEN is a string literal.  */
  
  static bool
*************** cp_parser_nested_name_specifier_opt (cp_
*** 3467,3484 ****
        /* Spot cases that cannot be the beginning of a
  	 nested-name-specifier.  On the second and subsequent times
  	 through the loop, we look for the `template' keyword.  */
!       if (success 
! 	  && cp_lexer_next_token_is_keyword (parser->lexer,
! 					     RID_TEMPLATE))
  	;
        /* A template-id can start a nested-name-specifier.  */
!       else if (cp_lexer_next_token_is (parser->lexer, CPP_TEMPLATE_ID))
  	;
        else
  	{
  	  /* If the next token is not an identifier, then it is
  	     definitely not a class-or-namespace-name.  */
! 	  if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME))
  	    break;
  	  /* If the following token is neither a `<' (to begin a
  	     template-id), nor a `::', then we are not looking at a
--- 3475,3491 ----
        /* Spot cases that cannot be the beginning of a
  	 nested-name-specifier.  On the second and subsequent times
  	 through the loop, we look for the `template' keyword.  */
!       token = cp_lexer_peek_token (parser->lexer);
!       if (success && token->keyword == RID_TEMPLATE)
  	;
        /* A template-id can start a nested-name-specifier.  */
!       else if (token->type == CPP_TEMPLATE_ID)
  	;
        else
  	{
  	  /* If the next token is not an identifier, then it is
  	     definitely not a class-or-namespace-name.  */
! 	  if (token->type != CPP_NAME)
  	    break;
  	  /* If the following token is neither a `<' (to begin a
  	     template-id), nor a `::', then we are not looking at a
*************** cp_parser_parse_definitely (parser)
*** 14844,14858 ****
    cp_parser_context_free_list = context;
  
    return !error_occurred;
- }
- 
- /* Returns non-zero if we are parsing tentatively.  */
- 
- static bool
- cp_parser_parsing_tentatively (parser)
-      cp_parser *parser;
- {
-   return parser->context->next != NULL;
  }
  
  /* Returns true if we are parsing tentatively -- but have decided that
--- 14851,14856 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]