Skip to content

misc: optimize out an strlen() call in ssh2_match_string() - #2425

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:ssh2_match_string-opt
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:ssh2_match_string-opt

Conversation

@vszakats

Copy link
Copy Markdown
Member

Copilot AI review requested due to automatic review settings July 24, 2026 11:49
@vszakats vszakats changed the title misc: de-duplicate strlen() calls in ssh2_match_string() misc: optimize out an strlen() call in ssh2_match_string() Jul 24, 2026

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 refactors ssh2_match_string() in src/misc.c to avoid recomputing the match string length, reducing redundant strlen() calls while preserving the existing matching semantics used during SSH packet/string parsing.

Changes:

  • Split the previous compound conditional into two steps: parse the SSH string first, then compare.
  • Cache strlen(match) into match_len and reuse it for both the length check and strncmp().

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

@vszakats vszakats closed this in f585681 Jul 24, 2026
@vszakats
vszakats deleted the ssh2_match_string-opt branch July 24, 2026 12:22
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