@@ -438,7 +438,6 @@ export class ComponentIdAllocator {
438438
439439const globalComponentIdAllocator = new ComponentIdAllocator ( ) ;
440440
441- const ComponentNames : Map < ComponentId < any > , string > = new Map ( ) ;
442441const ComponentIdForNames : Map < string , ComponentId < any > > = new Map ( ) ;
443442
444443/**
@@ -472,7 +471,8 @@ export interface ComponentOptions {
472471 dontFragment ?: boolean ;
473472}
474473
475- const ComponentOptions : Map < ComponentId < any > , ComponentOptions > = new Map ( ) ;
474+ // Array for component names (Component ID range: 1-1023)
475+ const componentNames : ( string | undefined ) [ ] = new Array ( COMPONENT_ID_MAX + 1 ) ;
476476
477477// BitSets for fast component option checks (Component ID range: 1-1023)
478478const exclusiveFlags = new BitSet ( COMPONENT_ID_MAX + 1 ) ;
@@ -513,13 +513,12 @@ export function component<T = void>(nameOrOptions?: string | ComponentOptions):
513513 throw new Error ( `Component name "${ name } " is already registered` ) ;
514514 }
515515
516- ComponentNames . set ( id , name ) ;
516+ componentNames [ id ] = name ;
517517 ComponentIdForNames . set ( name , id ) ;
518518 }
519519
520520 // Register options if provided
521521 if ( options ) {
522- ComponentOptions . set ( id , options ) ;
523522 // Set bitset flags for fast lookup
524523 if ( options . exclusive ) exclusiveFlags . set ( id ) ;
525524 if ( options . cascadeDelete ) cascadeDeleteFlags . set ( id ) ;
@@ -543,16 +542,28 @@ export function getComponentIdByName(name: string): ComponentId<any> | undefined
543542 * @returns The component name if found, undefined otherwise
544543 */
545544export function getComponentNameById ( id : ComponentId < any > ) : string | undefined {
546- return ComponentNames . get ( id ) ;
545+ return componentNames [ id ] ;
547546}
548547
549548/**
550549 * Get component options by its ID
551550 * @param id The component ID
552- * @returns The component options if found, undefined otherwise
551+ * @returns The component options
553552 */
554- export function getComponentOptions ( id : ComponentId < any > ) : ComponentOptions | undefined {
555- return ComponentOptions . get ( id ) ;
553+ export function getComponentOptions ( id : ComponentId < any > ) : ComponentOptions {
554+ if ( ! isComponentId ( id ) ) {
555+ throw new Error ( "Invalid component ID" ) ;
556+ }
557+ const hasName = componentNames [ id ] !== undefined ;
558+ const hasExclusive = exclusiveFlags . has ( id ) ;
559+ const hasCascadeDelete = cascadeDeleteFlags . has ( id ) ;
560+ const hasDontFragment = dontFragmentFlags . has ( id ) ;
561+ return {
562+ name : hasName ? componentNames [ id ] : undefined ,
563+ exclusive : hasExclusive ? true : undefined ,
564+ cascadeDelete : hasCascadeDelete ? true : undefined ,
565+ dontFragment : hasDontFragment ? true : undefined ,
566+ } ;
556567}
557568
558569/**
0 commit comments