Skip to content

Commit 5d83132

Browse files
committed
Store the list of known directive names in a set
This allows every check to be a single hashtable lookup instead of a linear scan.
1 parent f15a7f3 commit 5d83132

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::debuggers::{extract_cdb_version, extract_gdb_version};
1111
pub(crate) use crate::directives::auxiliary::AuxProps;
1212
use crate::directives::auxiliary::parse_and_update_aux;
1313
use crate::directives::directive_names::{
14-
KNOWN_DIRECTIVE_NAMES, KNOWN_HTMLDOCCK_DIRECTIVE_NAMES, KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
14+
KNOWN_DIRECTIVE_NAMES_SET, KNOWN_HTMLDOCCK_DIRECTIVE_NAMES, KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
1515
};
1616
pub(crate) use crate::directives::file::FileDirectives;
1717
use crate::directives::line::{DirectiveLine, line_directive};
@@ -786,7 +786,7 @@ fn check_directive<'a>(
786786
) -> CheckDirectiveResult<'a> {
787787
let &DirectiveLine { name: directive_name, .. } = directive_ln;
788788

789-
let is_known_directive = KNOWN_DIRECTIVE_NAMES.contains(&directive_name)
789+
let is_known_directive = KNOWN_DIRECTIVE_NAMES_SET.contains(&directive_name)
790790
|| match mode {
791791
TestMode::Rustdoc => KNOWN_HTMLDOCCK_DIRECTIVE_NAMES.contains(&directive_name),
792792
TestMode::RustdocJson => KNOWN_JSONDOCCK_DIRECTIVE_NAMES.contains(&directive_name),
@@ -799,7 +799,7 @@ fn check_directive<'a>(
799799
let trailing_directive = directive_ln
800800
.remark_after_space()
801801
.map(|remark| remark.trim_start().split(' ').next().unwrap())
802-
.filter(|token| KNOWN_DIRECTIVE_NAMES.contains(token));
802+
.filter(|token| KNOWN_DIRECTIVE_NAMES_SET.contains(token));
803803

804804
// FIXME(Zalathar): Consider emitting specialized error/help messages for
805805
// bogus directive names that are similar to real ones, e.g.:

src/tools/compiletest/src/directives/directive_names.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
use std::collections::HashSet;
2+
use std::sync::LazyLock;
3+
4+
pub(crate) static KNOWN_DIRECTIVE_NAMES_SET: LazyLock<HashSet<&str>> =
5+
LazyLock::new(|| KNOWN_DIRECTIVE_NAMES.iter().copied().collect());
6+
17
/// This was originally generated by collecting directives from ui tests and then extracting their
28
/// directive names. This is **not** an exhaustive list of all possible directives. Instead, this is
39
/// a best-effort approximation for diagnostics. Add new directives to this list when needed.

0 commit comments

Comments
 (0)