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
Reduce memory allocation in rules and utils #2976
Draft
willheslam
wants to merge
13
commits into
jsx-eslint:master
Choose a base branch
from
willheslam:optimisations
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+708
−514
Draft
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b4cd869
Curry read only props reporting function to avoid creating closures
willheslam 152a276
Replace Object.keys with values/entries
willheslam 35a88cb
Avoid allocating empty objects or arrays when possible
willheslam 69bcb8d
Speed up string manipulation and testing
willheslam da9231a
Speed up Components list by avoiding some array allocations and remov…
willheslam 8eff94d
Speed up Components utils
willheslam 671341e
Cache lower cased pragma
willheslam 0f7183e
Replace isFirstLetterCapitalised with regex check
willheslam 473d7c1
Replace array traversals with object property lookup
willheslam ccdd17c
Speed up no-deprecated
willheslam a2b5327
Preallocate arrays used as logical or equality checks
willheslam d16fcb3
Avoid recomputing expensive React version check
willheslam 232d6a1
Various speed ups by avoiding work and memory allocations
willheslam File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,22 +73,13 @@ module.exports = { | |
unsafe.componentWillUpdate = unsafe.UNSAFE_componentWillUpdate; | ||
} | ||
|
||
/** | ||
* Returns a list of unsafe methods | ||
* @returns {Array} A list of unsafe methods | ||
*/ | ||
function getUnsafeMethods() { | ||
return Object.keys(unsafe); | ||
} | ||
|
||
/** | ||
* Checks if a passed method is unsafe | ||
* @param {string} method Life cycle method | ||
* @returns {boolean} Returns true for unsafe methods, otherwise returns false | ||
*/ | ||
function isUnsafe(method) { | ||
const unsafeMethods = getUnsafeMethods(); | ||
return unsafeMethods.indexOf(method) !== -1; | ||
return (method in unsafe); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
|
||
/** | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why not use Sets here rather than
in
? also, usingin
here ensures we'll get false positives for things liketoString
, or anything else on Object.prototype.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.
Good catch on false positives with
in
, I definitely hadn't considered that.Set looks like a good fit here!