Commit 9354812
Optimize logger string formatting to avoid repeated allocations (#670)
Addresses feedback on PR #668 to eliminate inefficient string operations
in the logger's placeholder replacement logic.
### Changes
- **Removed repeated `find()` and `replace()` calls** that allocated new
buffers on each iteration
- **Build output directly into stringstream** by iterating through
`header_` once, appending arguments when "%@" placeholders are
encountered
### Before
```cpp
std::string formattedHeader = header_;
while ((pos = formattedHeader.find("%@", pos)) != std::string::npos) {
formattedHeader.replace(pos, 2, argStrings[argIndex]); // allocates + copies
pos += argStrings[argIndex].length();
++argIndex;
}
ss << formattedHeader;
```
### After
```cpp
for (size_t i = 0; i < header_.size(); ++i) {
if (i + 1 < header_.size() && header_[i] == '%' && header_[i + 1] == '@' &&
argIndex < argStrings.size()) {
ss << argStrings[argIndex];
++argIndex;
++i;
} else {
ss << header_[i];
}
}
```
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: chhwang <[email protected]>1 parent 77e5659 commit 9354812
1 file changed
+10
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
96 | 95 | | |
97 | | - | |
98 | 96 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
104 | 107 | | |
105 | 108 | | |
106 | | - | |
107 | | - | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
0 commit comments