Skip to content
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

perf: improve isBsonType #11846

Merged
merged 2 commits into from
May 28, 2022

Conversation

Uzlopak
Copy link
Collaborator

@Uzlopak Uzlopak commented May 28, 2022

Following the PR by @coyotte508 this PR improves the isBsonType function by avoiding the use of the actually heavy get-function.

@Uzlopak Uzlopak requested a review from AbdelrahmanHafez May 28, 2022 15:08
@Uzlopak Uzlopak changed the title Improve performance of isBsonType perf: improve isBsonType May 28, 2022
return (
typeof obj === 'object' &&
obj !== null &&
obj._bsontype === typename
Copy link
Contributor

@coyotte508 coyotte508 May 28, 2022

Choose a reason for hiding this comment

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

During my previous PR I was wondering whether or not to add an additional check, eg && obj.constructor.name !== 'Object' or && obj.constructor.name.localeCompare(typename, undefined, { sensitivity: 'accent' }) === 0, if someone ever decides to store json data with {_bsonType: xxx} inside

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dont think that this is necessary. The code change here is functionally equivalent to the previous code. If somebody really starts to create objects with their own _bsonType attribute, than it is their issue. ;)

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

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

One comment, but otherwise LGTM, thanks! 👍

@Uzlopak Uzlopak merged commit b11e22e into Automattic:master May 28, 2022
@Uzlopak Uzlopak deleted the improve-performance-of-isBsonType branch May 28, 2022 19:25
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