Skip to content

chore: refactor recursive search for markdown files#352

Merged
AndrewSouthpaw merged 7 commits into
thlorenz:masterfrom
thompson-tomo:patch-3
Apr 26, 2026
Merged

chore: refactor recursive search for markdown files#352
AndrewSouthpaw merged 7 commits into
thlorenz:masterfrom
thompson-tomo:patch-3

Conversation

@thompson-tomo

@thompson-tomo thompson-tomo commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Eliminate the statSync to optimise performance as that is often a costly operation which we do not need to be calling.

Overall optimisation of the get recursive ensuring streamlined operations and reduction in variable usage/allocations.

Comment thread lib/file.js Outdated
Comment thread lib/file.js
Comment on lines +11 to +12
function findRec(paths, syntax) {
var allowedExts = extensions[syntax] || [];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's making a copy of the paths to avoid mutating the param, slightly less spooky

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Aren't we already making a copy of by adding the param into an array on https://github.com/thlorenz/doctoc/pull/352/files#L50 which is the only way to enter this function?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, and technically right now it's fine, but it isn't obvious. Mutating a param is quite often an unexpected behavior. There's only you and me working on this codebase, so it's kinda moot, but someone who didn't know any better and didn't look at the contents of a function might use findRec and reasonably think paths doesn't get affected. It's a general clean coding practice, and in this case I don't see a compelling argument for a perf win to avoid defensive copying.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think I have changed it as suggested.

Comment thread lib/file.js
@thompson-tomo

Copy link
Copy Markdown
Contributor Author

@AndrewSouthpaw this is ready for another look.

@AndrewSouthpaw AndrewSouthpaw merged commit 96ca2b9 into thlorenz:master Apr 26, 2026
5 checks passed
@thompson-tomo thompson-tomo deleted the patch-3 branch April 26, 2026 02:56
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