-
Notifications
You must be signed in to change notification settings - Fork 40
I/6529: Inline is()
checks
#1836
Changes from all commits
36a629a
2e21618
e9071aa
4d6669c
13bdf60
b99b7a0
4e8b70c
029e8b2
19cd270
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,13 +116,14 @@ export default class Element extends Node { | |
* @returns {Boolean} | ||
*/ | ||
is( type, name = null ) { | ||
const cutType = type.replace( /^model:/, '' ); | ||
|
||
if ( !name ) { | ||
return cutType == 'element' || cutType == this.name || super.is( type ); | ||
} else { | ||
return cutType == 'element' && name == this.name; | ||
return type === 'element' || type === 'model:element' || | ||
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. One more optimization that you could consider is ordering those conditions in the likelihood of them being executed. You may need to do some stats and it's a subject of change, so we may need to repeat this. But if it yields nice results, it may be worth doing. 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. OK, I'll check this. Side note I've done some quick (I don't have the results saved though) check for the fastest 'false' path. I've counted the checks in the 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. I don't think that this will yield any significant result. I've done some tests and below are number of executions of some As you can see there are milions of checks using I don't see how we could optimize those paths reliably. At this stage I would try to |
||
type === this.name || type === 'model:' + this.name || | ||
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529. | ||
type === 'node' || type === 'model:node'; | ||
} | ||
|
||
return name === this.name && ( type === 'element' || type === 'model:element' ); | ||
} | ||
|
||
/** | ||
|
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.
When we talk about micro optimizations
name === null
may be faster.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.
Something doesn't work (maybe
undefined
is passed sometimes). Tests breaks after suggested change. Looking that this might be to micro optimization to care (looking on above times) I think we shouldn't dig into this more at this time.