[all-commits] [llvm/llvm-project] e38777: [ELF] Optimize ScriptLexer::getLineNumber by cachi...

colincross via All-commits all-commits at lists.llvm.org
Tue Jun 22 15:35:37 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e387778722f93705db903aa755529568a05dd9db
      https://github.com/llvm/llvm-project/commit/e387778722f93705db903aa755529568a05dd9db
  Author: Colin Cross <ccross at android.com>
  Date:   2021-06-22 (Tue, 22 Jun 2021)

  Changed paths:
    M lld/ELF/ScriptLexer.cpp
    M lld/ELF/ScriptLexer.h

  Log Message:
  -----------
  [ELF] Optimize ScriptLexer::getLineNumber by caching the previous line number and offset

getLineNumber() was counting the number of line feeds from the start of
the buffer to the current token. For large linker scripts this became a
performance bottleneck. For one 4MB linker script over 4 minutes was
spent in getLineNumber's StringRef::count.

Store the line number from the last token, and only count the additional
line feeds since the last token.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D104137




More information about the All-commits mailing list