Skip to content

Using RegExp replace loop in isHidden#109

Merged
niftylettuce merged 3 commits intokoajs:masterfrom
Jiasm:patch-1
May 15, 2020
Merged

Using RegExp replace loop in isHidden#109
niftylettuce merged 3 commits intokoajs:masterfrom
Jiasm:patch-1

Conversation

@Jiasm
Copy link
Copy Markdown
Contributor

@Jiasm Jiasm commented Aug 23, 2018

I think RegExp will faster than loop.

Copy link
Copy Markdown
Member

@3imed-jaberi 3imed-jaberi left a comment

Choose a reason for hiding this comment

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

LGTM 🚀, this my nano suggestion !!

function isHidden (root, path) {
  const hiddenFileReg = new RegExp(`${sep}\\.`)
  path = path.substr(root.length)

  return hiddenFileReg.test(path)
}

@Jiasm
Copy link
Copy Markdown
Contributor Author

Jiasm commented May 15, 2020

@3imed-jaberi sep is a constant, so i define hiddenFileReg in module scope.😄

@niftylettuce niftylettuce merged commit 8330028 into koajs:master May 15, 2020
niftylettuce added a commit that referenced this pull request May 15, 2020
niftylettuce added a commit that referenced this pull request May 15, 2020
@niftylettuce
Copy link
Copy Markdown
Contributor

I'm reverting this. Generally RegExp is unsafe in JavaScript, and for loops are incredibly fast.

Without a performance test nor benchmark, I cannot merge this. Sorry for the accident merge.

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.

3 participants