-
Notifications
You must be signed in to change notification settings - Fork 6.2k
perf: optimize regex usage and field access across codebase #5376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…lename handling Signed-off-by: Balázs Szücs <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request optimizes regex usage across the codebase by compiling frequently-used regex patterns as static constants rather than recompiling them on each use. Additionally, it refactors field access patterns and improves code efficiency through Map.Entry usage in loops.
Key Changes:
- Refactored regex operations to use pre-compiled Pattern constants across multiple service and controller classes, improving performance for frequently-executed operations
- Replaced getter method calls with direct field access in several model classes (Role.java, Provider.java, AuditEventType.java) for improved clarity
- Optimized loop iterations in EndpointConfiguration.java to use Map.Entry instead of repeated key-based lookups
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| SignatureService.java | Added VALID_FILENAME_PATTERN constant and made ALL_USERS_FOLDER static final |
| SharedSignatureService.java | Added VALID_FILENAME_PATTERN constant and made ALL_USERS_FOLDER static final |
| PdfJsonFallbackFontService.java | Added Pattern constants for bold weight detection, delimiter splitting, and whitespace handling |
| PdfJsonConversionService.java | Added Pattern constants for whitespace, normalization, and subset prefix removal |
| ReactRoutingController.java | Added BASE_HREF_PATTERN constant for HTML base tag replacement |
| PipelineDirectoryProcessor.java | Added WATCHED_FOLDERS_PATTERN constant for directory path processing |
| PageNumbersController.java | Added FILE_EXTENSION_PATTERN constant for filename processing |
| ConvertPdfJsonController.java | Added FILE_EXTENSION_PATTERN constant for filename processing |
| MergeController.java | Added QUOTE_REMOVAL_PATTERN constant for quote stripping |
| BookletImpositionController.java | Added FILE_EXTENSION_PATTERN constant for filename processing |
| ConvertWebsiteToPdfTest.java | Added PDF_FILENAME_PATTERN constant for test assertions |
| AuditEventType.java | Replaced getter call with direct field access |
| Provider.java | Replaced getter calls with direct field access in toString() |
| Role.java | Replaced getter calls with direct field access in multiple methods |
| CreateSignatureBase.java | Replaced setter calls with direct field assignment |
| ReplaceAndInvertColorStrategy.java | Replaced setter call with direct field assignment |
| YamlHelper.java | Fixed bug by assigning updated node directly instead of using setter |
| EndpointConfiguration.java | Refactored loops to use Map.Entry for improved efficiency |
| SPDFApplication.java | Reorganized methods (moved printStartupLogs and related methods) with no functional changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description of Changes
This pull request primarily focuses on code quality improvements and minor refactoring across several modules. The main themes are: refactoring for clarity and efficiency, standardizing file extension and quote removal logic in controllers, and minor bug fixes and consistency improvements. No major new features are introduced.
Refactoring and Code Quality Improvements:
EndpointConfiguration.javato useMap.Entryinstead of repeatedly fetching values by key, improving efficiency and readability in endpoint group checks.Role.javaandProvider.javafor improved clarity and consistency.ReplaceAndInvertColorStrategy.javaandCreateSignatureBase.javato use direct field assignment instead of setter methods for better transparency and code simplicity.YamlHelper.javaby assigning the updated node directly toupdatedRootNodeinstead of using a setter, ensuring correct state updates.Controller Logic Standardization:
Standardized file extension removal logic across multiple controllers (
BookletImpositionController,ConvertPdfJsonController,PageNumbersController) by using a sharedPatternandmatcher.replaceFirst("")instead of inline regex replacements, improving maintainability and reducing duplication.Standardized quote removal in
MergeControllerby compiling the regex pattern once and reusing it, instead of usingreplaceAllinline.Application Startup and Logging:
Refactored
SPDFApplication.javato move startup log printing and server port handling into dedicated methods, and improved logging for runtime port assignment. Also removed obsolete desktop UI cleanup code.Miscellaneous:
Patternin several controllers to support the new regex-based logic.Checklist
General
Documentation
Translations (if applicable)
scripts/counter_translation.pyUI Changes (if applicable)
Testing (if applicable)