mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:24:20 +00:00
perf(parsers): remove hot-loop allocs in UEFI, USN, PE, Go, Rust, Maven (#13647)
perf(parsers): eliminate hot-loop allocs in UEFI, NTFS USN, PE, Go, Rust, and Maven
This commit is contained in:
1 parent
8018344145
commit
841d41df31
6 files changed
+87
-60
No files matched your search
@@ -48,21 +48,47 @@ const childElements = (element: Element): Element[] => {
|
||||
return children;
|
||||
};
|
||||
|
||||
const childrenNamed = (element: Element, ...names: string[]): Element[] =>
|
||||
childElements(element).filter(
|
||||
(child) =>
|
||||
(child.namespaceURI ?? "") === (element.namespaceURI ?? "") &&
|
||||
const childrenNamed = (element: Element, ...names: string[]): Element[] => {
|
||||
const ns = element.namespaceURI ?? "";
|
||||
const matches: Element[] = [];
|
||||
for (
|
||||
let child = element.firstChild;
|
||||
child !== null;
|
||||
child = child.nextSibling
|
||||
) {
|
||||
if (
|
||||
isElement(child) &&
|
||||
(child.namespaceURI ?? "") === ns &&
|
||||
child.localName !== null &&
|
||||
names.includes(child.localName),
|
||||
);
|
||||
names.includes(child.localName)
|
||||
)
|
||||
matches.push(child);
|
||||
}
|
||||
return matches;
|
||||
};
|
||||
|
||||
const soleNamed = (element: Element, local: string): Element | undefined => {
|
||||
const matches = childrenNamed(element, local);
|
||||
if (matches.length <= 1) return matches[0];
|
||||
throw malformedInput(
|
||||
MAVEN_GRADLE_METADATA_FORMAT,
|
||||
`Maven POM declares <${local}> more than once in one <${element.localName}>.`,
|
||||
);
|
||||
const ns = element.namespaceURI ?? "";
|
||||
let found: Element | undefined;
|
||||
for (
|
||||
let child = element.firstChild;
|
||||
child !== null;
|
||||
child = child.nextSibling
|
||||
) {
|
||||
if (
|
||||
isElement(child) &&
|
||||
(child.namespaceURI ?? "") === ns &&
|
||||
child.localName === local
|
||||
) {
|
||||
if (found !== undefined)
|
||||
throw malformedInput(
|
||||
MAVEN_GRADLE_METADATA_FORMAT,
|
||||
`Maven POM declares <${local}> more than once in one <${element.localName}>.`,
|
||||
);
|
||||
found = child;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
};
|
||||
|
||||
const MAVEN_POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0";
|
||||
|
||||
Reference in new issue
Block a user