MCPcopy
hub / github.com/facebook/react / findSharedIndex

Function findSharedIndex

packages/react-debug-tools/src/ReactDebugHooks.js:847–870  ·  view source on GitHub ↗
(
  hookStack: ParsedStackFrame[],
  rootStack: ParsedStackFrame[],
  rootIndex: number,
)

Source from the content-addressed store, hash-verified

845let mostLikelyAncestorIndex = 0;
846
847function findSharedIndex(
848 hookStack: ParsedStackFrame[],
849 rootStack: ParsedStackFrame[],
850 rootIndex: number,
851) {
852 const source = rootStack[rootIndex].source;
853 hookSearch: for (let i = 0; i < hookStack.length; i++) {
854 if (hookStack[i].source === source) {
855 // This looks like a match. Validate that the rest of both stack match up.
856 for (
857 let a = rootIndex + 1, b = i + 1;
858 a < rootStack.length && b < hookStack.length;
859 a++, b++
860 ) {
861 if (hookStack[b].source !== rootStack[a].source) {
862 // If not, give up and try a different match.
863 continue hookSearch;
864 }
865 }
866 return i;
867 }
868 }
869 return -1;
870}
871
872function findCommonAncestorIndex(
873 rootStack: ParsedStackFrame[],

Callers 1

findCommonAncestorIndexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected