// Copyright 2025 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
// Registry for mapping element-template handle IDs to native refs.
//
// Main-thread IFR allocates IDs as consecutive negative integers: -1, -2, -3...
// We store those in a dense array for performance.
//
// Other IDs (e.g. positive IDs coming from background-created nodes) fall back to a Map.
const negativeRefs = [];
const otherRefs = new Map();
export function setElementTemplateNativeRef(id, nativeRef) {
    if (id < 0) {
        negativeRefs[-id - 1] = nativeRef;
        return;
    }
    otherRefs.set(id, nativeRef);
}
export function getElementTemplateNativeRef(id) {
    if (id < 0) {
        return negativeRefs[-id - 1];
    }
    return otherRefs.get(id);
}
export function hasElementTemplateNativeRef(id) {
    return getElementTemplateNativeRef(id) != null;
}
export function deleteElementTemplateNativeRef(id) {
    if (id < 0) {
        negativeRefs[-id - 1] = undefined;
        return;
    }
    otherRefs.delete(id);
}
export function clearElementTemplateNativeRefRegistry() {
    negativeRefs.length = 0;
    otherRefs.clear();
}
export const elementTemplateRegistry = {
    set: setElementTemplateNativeRef,
    get: getElementTemplateNativeRef,
    has: hasElementTemplateNativeRef,
    delete: deleteElementTemplateNativeRef,
    clear: clearElementTemplateNativeRefRegistry,
};
//# sourceMappingURL=registry.js.map