You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
0 commit comments