Skip to content

perf: use static regex instances and test cleanup#998

Merged
annejan merged 1 commit intomainfrom
fix/regex-optimization-test-cleanup
Apr 13, 2026
Merged

perf: use static regex instances and test cleanup#998
annejan merged 1 commit intomainfrom
fix/regex-optimization-test-cleanup

Conversation

@nogeenhenk
Copy link
Copy Markdown
Contributor

@nogeenhenk nogeenhenk commented Apr 13, 2026

User description

Summary

  • Use static const QRegularExpression instances in isValidKeyId and findBinaryInPath to avoid creating objects on each call
  • Add PassStoreGuard to tests that modify QtPassSettings::setPassStore for proper cleanup

Changes

  • src/util.cpp: Add static regexes for hexPrefixRegex, specialPrefixRegex, hexKeyIdRegex, whitespaceRegex
  • tests/auto/util/tst_util.cpp: Add PassStoreGuard to getRecipientListBasic, getGpgIdPathBasic, getGpgIdPathSubfolder, getGpgIdPathNotFound

CodeAnt-AI Description

Speed up key ID checks and keep test settings isolated

What Changed

  • Key ID validation now reuses the same pattern checks instead of recreating them on each call
  • Windows binary lookup now reuses the same whitespace check before trying the WSL fallback
  • Tests that change the pass store now clean up after themselves so later tests keep the right settings

Impact

✅ Faster key ID validation
✅ Lower overhead during binary lookup
✅ Fewer test setting leaks

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

- Add static const QRegularExpression for hexPrefixRegex, specialPrefixRegex,
  hexKeyIdRegex in isValidKeyId to avoid creating objects on each call
- Add static const whitespaceRegex in findBinaryInPath
- Add PassStoreGuard to getRecipientListBasic, getGpgIdPathBasic,
  getGpgIdPathSubfolder, getGpgIdPathNotFound for proper test cleanup
@codeant-ai
Copy link
Copy Markdown
Contributor

codeant-ai bot commented Apr 13, 2026

CodeAnt AI is reviewing your PR.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 83dcc5d0-dc93-4bd6-a123-7a4bc5fc52de

📥 Commits

Reviewing files that changed from the base of the PR and between 74f09dd and 89c6cf8.

📒 Files selected for processing (2)
  • src/util.cpp
  • tests/auto/util/tst_util.cpp

📝 Walkthrough

Walkthrough

This PR refactors regex pattern usage in src/util.cpp by consolidating repeated inline QRegularExpression constructions into static const instances, and improves test isolation by introducing PassStoreGuard to safely manage global state restoration instead of unguarded mutations.

Changes

Cohort / File(s) Summary
Regex Pattern Consolidation
src/util.cpp
Replaces inline QRegularExpression construction in findBinaryInPath (WSL whitespace validation) and isValidKeyId (hex key-id and prefix validation) with shared static const regex objects to avoid repeated pattern compilation.
Test Isolation Improvements
tests/auto/util/tst_util.cpp
Four tests now wrap pass store manipulation with PassStoreGuard to automatically restore the original QtPassSettings::getPassStore() value, replacing unguarded global state mutations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size:S

Poem

A rabbit hops through patterns bright,
Static const regexes cached just right,
Guards now shelter tests with care,
No state leaks left floating in air! 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: performance optimization through static regex instances and test cleanup with proper state management.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/regex-optimization-test-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeant-ai codeant-ai bot added the size:S This PR changes 10-29 lines, ignoring generated files label Apr 13, 2026
@codeant-ai
Copy link
Copy Markdown
Contributor

codeant-ai bot commented Apr 13, 2026

CodeAnt AI finished reviewing your PR.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 21.004% (+0.04%) from 20.96% — fix/regex-optimization-test-cleanup into main

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 27.12%. Comparing base (74f09dd) to head (89c6cf8).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #998      +/-   ##
==========================================
+ Coverage   27.06%   27.12%   +0.06%     
==========================================
  Files          39       39              
  Lines        3311     3314       +3     
==========================================
+ Hits          896      899       +3     
  Misses       2415     2415              
Flag Coverage Δ
qtpass 27.12% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@annejan annejan merged commit c6f2f11 into main Apr 13, 2026
26 checks passed
@annejan annejan deleted the fix/regex-optimization-test-cleanup branch April 13, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants