[lld] [ELF] ScriptLexer: generate tokens lazily (PR #100493)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 03:58:26 PDT 2024


================
@@ -1098,12 +1113,31 @@ SymbolAssignment *ScriptParser::readProvideHidden(bool provide, bool hidden) {
   return cmd;
 }
 
+// Replace whitespace sequence (including \n) with one single space. The output
+// is used by -Map.
+static void squeezeSpaces(std::string &str) {
----------------
smithp35 wrote:

I was wondering if there was a way of writing this using algorthim's but I think the end result was worse, it also has the property of removing all leading white-space (which may not be a problem if that's been skipped already).

Best I came up with:
```
  std::replace_if(
      s.begin(), s.end(), [](char c) { return isspace(c); }, ' ');
  s.erase(std::unique(s.begin(), s.end(),
                      [](char lhs, char rhs) {
    return lhs == ' ' && rhs == ' '; }),
          s.end();
```

https://github.com/llvm/llvm-project/pull/100493


More information about the llvm-commits mailing list