(s: &[u8])
| 430 | tags: Vec<String>, |
| 431 | } |
| 432 | |
| 433 | fn scan_inline_structs(s: &[u8]) -> InlineScan { |
| 434 | let mut out = InlineScan { ptr: false, types: Vec::new(), tags: Vec::new() }; |
| 435 | let mut last = 0; |
| 436 | // Where each keyword next stands, looked for again only once the scan has |
| 437 | // passed it. Looked for from `last` on every turn, the one a file does not |
| 438 | // use was searched for to the end of the file for each of the other: a |
| 439 | // header of twenty thousand structs and no union read itself that many times. |
| 440 | let mut next_struct = find_word(s, b"struct", 0); |
| 441 | let mut next_union = find_word(s, b"union", 0); |
| 442 | loop { |
| 443 | if next_struct.is_some_and(|at| at < last) { |
| 444 | next_struct = find_word(s, b"struct", last); |
| 445 | } |
| 446 | if next_union.is_some_and(|at| at < last) { |
| 447 | next_union = find_word(s, b"union", last); |
| 448 | } |
| 449 | let Some((t, keyword_len)) = (match (next_struct, next_union) { |
| 450 | (Some(st), Some(un)) if st < un => Some((st, 6)), |
| 451 | (Some(_), Some(un)) => Some((un, 5)), |
| 452 | (Some(st), None) => Some((st, 6)), |
| 453 | (None, Some(un)) => Some((un, 5)), |
| 454 | (None, None) => None, |
| 455 | }) else { |
| 456 | break; |
| 457 | }; |
| 458 | let after_kw = t + keyword_len; |
| 459 | let ws = skip_jsws(s, after_kw); |
| 460 | if ws == after_kw || !is_word_at(s, ws) { |
| 461 | last = t + 1; |
| 462 | continue; |
| 463 | } |
| 464 | let te = word_end(s, ws); |
| 465 | let open = skip_jsws(s, te); |
| 466 | if s.get(open) != Some(&b'{') { |
| 467 | last = t + 1; |
| 468 | continue; |
| 469 | } |
| 470 | last = open + 1; // lastIndex = end of match (after `{`) |
| 471 | let Some(close) = match_brace(s, open) else { continue }; |
| 472 | // vm: /^\s*(\w+)…/ on the text after `}` — only vm[1] matters here. |
| 473 | let v = skip_jsws(s, close + 1); |
| 474 | if !is_word_at(s, v) { |
| 475 | continue; |
| 476 | } |
| 477 | push_str(&mut out.tags, &s[ws..te]); |
| 478 | for f in parse_struct_fields_raw(&s[open + 1..close]) { |
| 479 | if f.name.is_empty() { |
| 480 | continue; |
| 481 | } |
| 482 | if f.ptr { |
| 483 | out.ptr = true; |
| 484 | } else if !f.ty.is_empty() { |
| 485 | out.types.push(f.ty); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | out |
no test coverage detected