-
Notifications
You must be signed in to change notification settings - Fork 5.2k
check: return instead of throw internally #4584
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
Conversation
@@ -145,33 +139,41 @@ var typeofChecks = [ | |||
[undefined, "undefined"] | |||
]; | |||
|
|||
var checkSubtree = function (value, pattern) { | |||
// Return `false` if it matches. Otherwise, return an object with a `message` and a `path` field. | |||
var testSubtree = function (value, pattern) { |
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.
This doesn't correspond to test
the way checkSubtree
corresponded to check
.
@wh0: Before we can merge your pull request, you'll need to sign the Meteor Contributor Agreement: https://contribute.meteor.com/ |
❤️ |
if (value === null) | ||
throw new Match.Error("Expected object, got null"); | ||
return { |
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.
Since these if statements have become multiple lines, let's wrap the body in brackets.
@wh0 still waiting on the for loop change! Excited to get this change in. |
Yea! |
Why closing? |
whoa, I accidentally deleted my branch |
Lol, I should merge this |
Yes you should. :-) |
Profiling our teams app showed that a lot of time was spent creating errors for the
check
package, which I assume creates a stack trace each time. For everyMatch.Optional
orMatch.OneOf
, it would have to create a stack trace for the one choice that failed.Anyway, this PR modifies
check
's internal implementation to use morereturn
instead ofthrow
, so as not to construct so many error objects. It shouldn't change the external API ofcheck
orMatch.Where
.This sped up one of our app's benchmarks, which called
Collection::find
many times (find
internally usescheck
to validate its second parameter).