refactor(linter): reduce repeated code#13070
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #13070 will not alter performanceComparing Summary
Footnotes |
There was a problem hiding this comment.
Pull Request Overview
This refactor simplifies the process_path method by extracting duplicated return logic into a separate helper function. The change eliminates multiple instances of creating default ModuleProcessOutput with cloned path values.
- Extracted core processing logic into
process_path_to_modulehelper function - Replaced multiple
default_output()calls with early returns using?operator - Simplified error handling flow by using
Option<ProcessedModule>return type
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Merge activity
|
Refactor. Many branches of `process_path` return a default `ProcessedModule`. All branches return a `ModuleProcessOutput` with `path` field containing a clone of `path` param. Move the duplicated logic into a separate function, to allow shortening and simplifying the logic. There may be a small perf benefit of not repeating the same code in many places, but mainly the motivation is to shorten the code, which I find makes it a bit easier to understand.
a0c16b9 to
103c51b
Compare
Refactor. Many branches of `process_path` return a default `ProcessedModule`. All branches return a `ModuleProcessOutput` with `path` field containing a clone of `path` param. Move the duplicated logic into a separate function, to allow shortening and simplifying the logic. There may be a small perf benefit of not repeating the same code in many places, but mainly the motivation is to shorten the code, which I find makes it a bit easier to understand.
103c51b to
74fb6c9
Compare
Further refactor of `process_path`, continuing from #13070. Avoid unnecessary pre-initialization of `records` and `module_content`, when mostly they're overwritten later. Instead, each branch of the `if` / `else` hold their own vars, and construct a `ProcessedModule`. There may be some tiny perf benefit of skipping the initializations, but mainly motivation is to make it more explicit what each branch returns, which personally I find makes the logic easier to follow. Also de-duplicate creation of `allocator_guard`, which was previously repeated in both branches.

Refactor. Many branches of
process_pathreturn a defaultProcessedModule. All branches return aModuleProcessOutputwithpathfield containing a clone ofpathparam.Move the duplicated logic into a separate function, to allow shortening and simplifying the logic.
There may be a small perf benefit of not repeating the same code in many places, but mainly the motivation is to shorten the code, which I find makes it a bit easier to understand.