This came up during the codereview here: https://bugs.webkit.org/show_bug.cgi?id=208311#c53 Darin Adler said: "Can’t help noticing that this function is not written with efficiency in mind. The nodeType virtual function is pretty expensive and we call it 3 times!" and "this can be optimized for all the common cases to not call nodeType at all, using functions like isElementNode and isTextNode that are inline single bit checks. Only exotic cases would require calls to nodeType."
I do want to be a bit cautious about not complicating this to optimize it if there’s no evidence a faster version would make any practical difference. So maybe we shouldn’t do it even though I suggested it. Would be easy to do, though.