mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
perf(ast): faster Comment::is_jsdoc (#7905)
Small optimization. Replace string slice + `starts_with` (at least 3 x bounds checks + 2 x UTF8 character boundary checks) with a single byte read (1 x bounds check).
This commit is contained in:
parent
b99ee37326
commit
a5f04a72b5
1 changed files with 4 additions and 3 deletions
|
|
@ -104,9 +104,10 @@ impl Comment {
|
|||
/// Returns `true` if this comment is a JSDoc comment. Implies `is_leading`
|
||||
/// and `is_block`.
|
||||
pub fn is_jsdoc(&self, source_text: &str) -> bool {
|
||||
self.is_leading()
|
||||
&& self.is_block()
|
||||
&& self.content_span().source_text(source_text).starts_with('*')
|
||||
self.is_leading() && self.is_block() && {
|
||||
let span = self.content_span();
|
||||
!span.is_empty() && source_text.as_bytes()[span.start as usize] == b'*'
|
||||
}
|
||||
}
|
||||
|
||||
/// Legal comments
|
||||
|
|
|
|||
Loading…
Reference in a new issue