{"ScriptPreparationCode":"// --- ENUMS \u0026 CONSTANTS ---\r\nvar ClrPopoverType = {\r\n SIGNPOST: 0,\r\n TOOLTIP: 1,\r\n DROPDOWN: 2,\r\n DEFAULT: 3\r\n};\r\n\r\nvar ClrPopoverPosition = {\r\n TOP_LEFT: \u0027top-left\u0027,\r\n TOP_RIGHT: \u0027top-right\u0027,\r\n BOTTOM_LEFT: \u0027bottom-left\u0027,\r\n BOTTOM_RIGHT: \u0027bottom-right\u0027,\r\n LEFT_TOP: \u0027left-top\u0027,\r\n RIGHT_TOP: \u0027right-top\u0027\r\n};\r\n\r\nvar POPOVER_OFFSETS = {\r\n 0: 16, // Signpost\r\n 1: 21, // Tooltip\r\n 2: 2, // Dropdown\r\n 3: 0 // Default\r\n};\r\n\r\n// A list of 12 positions to simulate the loop in the original code\r\nvar SIGNPOST_POSITIONS = [\r\n ClrPopoverPosition.TOP_LEFT, ClrPopoverPosition.TOP_RIGHT,\r\n ClrPopoverPosition.BOTTOM_LEFT, ClrPopoverPosition.BOTTOM_RIGHT,\r\n ClrPopoverPosition.LEFT_TOP, ClrPopoverPosition.RIGHT_TOP,\r\n \u0027right-middle\u0027, \u0027left-middle\u0027, \u0027top-middle\u0027, \u0027bottom-middle\u0027,\r\n \u0027right-bottom\u0027, \u0027left-bottom\u0027\r\n];\r\n\r\n// --- 1. THE SWITCH IMPLEMENTATION (LEGACY) ---\r\nfunction getPositions_Switch(type) {\r\n var positionsToCheck;\r\n \r\n // Simulate the switch to select array\r\n switch (type) {\r\n case ClrPopoverType.TOOLTIP: positionsToCheck = SIGNPOST_POSITIONS; break; // simplified\r\n case ClrPopoverType.DROPDOWN: positionsToCheck = SIGNPOST_POSITIONS; break; // simplified\r\n default: positionsToCheck = SIGNPOST_POSITIONS; break;\r\n }\r\n\r\n // Map to new objects (Allocation happens here)\r\n return positionsToCheck.map(function(pos) {\r\n return createPositionObject_Switch(pos, type);\r\n });\r\n}\r\n\r\nfunction createPositionObject_Switch(key, type) {\r\n var offset = POPOVER_OFFSETS[type] || 0;\r\n \r\n // Simulate the massive Switch-Case for creating the object\r\n switch (key) {\r\n case ClrPopoverPosition.TOP_LEFT:\r\n return { originX: \u0027start\u0027, originY: \u0027top\u0027, overlayX: \u0027start\u0027, overlayY: \u0027bottom\u0027, offsetY: -offset };\r\n case ClrPopoverPosition.TOP_RIGHT:\r\n return { originX: \u0027end\u0027, originY: \u0027top\u0027, overlayX: \u0027end\u0027, overlayY: \u0027bottom\u0027, offsetY: -offset };\r\n case ClrPopoverPosition.BOTTOM_LEFT:\r\n return { originX: \u0027start\u0027, originY: \u0027bottom\u0027, overlayX: \u0027start\u0027, overlayY: \u0027top\u0027, offsetY: offset };\r\n default:\r\n return { originX: \u0027center\u0027, originY: \u0027center\u0027, overlayX: \u0027center\u0027, overlayY: \u0027center\u0027, offsetY: 0 };\r\n }\r\n}\r\n\r\n// --- 2. THE MAP/CACHE IMPLEMENTATION (OPTIMIZED) ---\r\nvar POSITION_CACHE = new Map();\r\n\r\n// Static Config Map\r\nvar CONFIG_MAP = {};\r\nCONFIG_MAP[ClrPopoverPosition.TOP_LEFT] = { origin: {originX: \u0027start\u0027, originY: \u0027top\u0027}, overlay: {overlayX: \u0027start\u0027, overlayY: \u0027bottom\u0027} };\r\nCONFIG_MAP[ClrPopoverPosition.TOP_RIGHT] = { origin: {originX: \u0027end\u0027, originY: \u0027top\u0027}, overlay: {overlayX: \u0027end\u0027, overlayY: \u0027bottom\u0027} };\r\nCONFIG_MAP[ClrPopoverPosition.BOTTOM_LEFT] = { origin: {originX: \u0027start\u0027, originY: \u0027bottom\u0027}, overlay: {overlayX: \u0027start\u0027, overlayY: \u0027top\u0027} };\r\n\r\nfunction getPositions_Cached(type) {\r\n // 1. Check Cache\r\n if (POSITION_CACHE.has(type)) {\r\n return POSITION_CACHE.get(type);\r\n }\r\n\r\n // 2. Generate (Only once)\r\n var result = SIGNPOST_POSITIONS.map(function(pos) {\r\n return createPositionObject_Map(pos, type);\r\n });\r\n\r\n // 3. Freeze \u0026 Save\r\n Object.freeze(result);\r\n POSITION_CACHE.set(type, result);\r\n return result;\r\n}\r\n\r\nfunction createPositionObject_Map(key, type) {\r\n var offset = POPOVER_OFFSETS[type] || 0;\r\n var config = CONFIG_MAP[key] || { origin: {originX: \u0027center\u0027}, overlay: {overlayX: \u0027center\u0027} };\r\n \r\n var result = {\r\n originX: config.origin.originX,\r\n originY: config.origin.originY,\r\n overlayX: config.overlay.overlayX,\r\n overlayY: config.overlay.overlayY,\r\n offsetY: key.indexOf(\u0027top\u0027) \u003E -1 ? -offset : offset\r\n };\r\n \r\n Object.freeze(result);\r\n return result;\r\n}","TestCases":[{"Name":"Switch statement","Code":"// Simulate 100 components requesting positions\r\nfor (var i = 0; i \u003C 100; i\u002B\u002B) {\r\n var result = getPositions_Switch(ClrPopoverType.SIGNPOST);\r\n // Access a value to ensure engine doesn\u0027t optimize away\r\n var check = result[0].originX; \r\n}","IsDeferred":false},{"Name":"Map statement","Code":"// Simulate 100 components requesting positions\r\nfor (var i = 0; i \u003C 100; i\u002B\u002B) {\r\n var result = getPositions_Cached(ClrPopoverType.SIGNPOST);\r\n // Access a value to ensure engine doesn\u0027t optimize away\r\n var check = result[0].originX;\r\n}","IsDeferred":false}]}