Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

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

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

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];
  }
}

💡 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 in the docs.

Copilot AI changed the title [WIP] Fix efficiency issues in logger string handling Optimize logger string formatting to avoid repeated allocations Oct 31, 2025
Copilot AI requested a review from chhwang October 31, 2025 19:58
Copilot finished work on behalf of chhwang October 31, 2025 19:58
@chhwang chhwang marked this pull request as ready for review November 3, 2025 23:52
@chhwang chhwang merged commit 9354812 into chhwang/logger Nov 3, 2025
1 check passed
@chhwang chhwang deleted the copilot/sub-pr-668 branch November 3, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants