[lld] [ELF] ScriptLexer: generate tokens lazily (PR #100493)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 09:45:02 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) {
----------------
MaskRay wrote:
I agree that `<algorithm>` functions might make the algorithm more difficult to read. It will likely require two passes. I've now changed this to a more clever loop:
```cpp
static void squeezeSpaces(std::string &str) {
char prev = '\0';
auto it = str.begin();
for (char c : str)
if (!isSpace(c) || (c = ' ') != prev)
*it++ = prev = c;
str.erase(it, str.end());
}
```
https://github.com/llvm/llvm-project/pull/100493
More information about the llvm-commits
mailing list