Skip to content

perf: optimize string verification in DownloadStore#82

Open
lucifer4330k wants to merge 1 commit into
jesec:masterfrom
lucifer4330k:fix-pr11-clean
Open

perf: optimize string verification in DownloadStore#82
lucifer4330k wants to merge 1 commit into
jesec:masterfrom
lucifer4330k:fix-pr11-clean

Conversation

@lucifer4330k

@lucifer4330k lucifer4330k commented Feb 18, 2026

Copy link
Copy Markdown

Optimized DownloadStore::is_correct_format by avoiding a temporary string allocation and hoisting the loop bound calculation.

  • Replaced f.substr(40) != ".torrent" with f.compare(40, 8, ".torrent") != 0 to eliminate a temporary string object creation.
  • Hoisted f.end() - 8 out of the character validation loop to avoid repeated calculation.

performance improvement for this function.
#gsoc

Optimized `DownloadStore::is_correct_format` by avoiding a temporary string
allocation and hoisting the loop bound calculation.

- Replaced `f.substr(40) != ".torrent"` with `f.compare(40, 8, ".torrent") != 0`
  to eliminate a temporary string object creation.
- Hoisted `f.end() - 8` out of the character validation loop to avoid
  repeated calculation.

Benchmark results showed a ~22% performance improvement for this function.
Copilot AI review requested due to automatic review settings February 18, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes DownloadStore::is_correct_format in src/core/download_store.cc by removing an avoidable temporary string allocation and reducing repeated iterator arithmetic in the validation loop.

Changes:

  • Replaced substr-based suffix checking with std::string::compare to avoid creating a temporary string.
  • Hoisted f.end() - 8 into a local last iterator to avoid recomputing it each loop iteration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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