MCPcopy Index your code
hub / github.com/plotly/dash / pushTreeId

Function pushTreeId

dash/deps/react-dom@18.2.0.js:12124–12180  ·  view source on GitHub ↗
(workInProgress, totalChildren, index)

Source from the content-addressed store, hash-verified

12122 treeForkCount = totalChildren;
12123 }
12124 function pushTreeId(workInProgress, totalChildren, index) {
12125 warnIfNotHydrating();
12126 idStack[idStackIndex++] = treeContextId;
12127 idStack[idStackIndex++] = treeContextOverflow;
12128 idStack[idStackIndex++] = treeContextProvider;
12129 treeContextProvider = workInProgress;
12130 var baseIdWithLeadingBit = treeContextId;
12131 var baseOverflow = treeContextOverflow; // The leftmost 1 marks the end of the sequence, non-inclusive. It's not part
12132 // of the id; we use it to account for leading 0s.
12133
12134 var baseLength = getBitLength(baseIdWithLeadingBit) - 1;
12135 var baseId = baseIdWithLeadingBit & ~(1 << baseLength);
12136 var slot = index + 1;
12137 var length = getBitLength(totalChildren) + baseLength; // 30 is the max length we can store without overflowing, taking into
12138 // consideration the leading 1 we use to mark the end of the sequence.
12139
12140 if (length > 30) {
12141 // We overflowed the bitwise-safe range. Fall back to slower algorithm.
12142 // This branch assumes the length of the base id is greater than 5; it won't
12143 // work for smaller ids, because you need 5 bits per character.
12144 //
12145 // We encode the id in multiple steps: first the base id, then the
12146 // remaining digits.
12147 //
12148 // Each 5 bit sequence corresponds to a single base 32 character. So for
12149 // example, if the current id is 23 bits long, we can convert 20 of those
12150 // bits into a string of 4 characters, with 3 bits left over.
12151 //
12152 // First calculate how many bits in the base id represent a complete
12153 // sequence of characters.
12154 var numberOfOverflowBits = baseLength - baseLength % 5; // Then create a bitmask that selects only those bits.
12155
12156 var newOverflowBits = (1 << numberOfOverflowBits) - 1; // Select the bits, and convert them to a base 32 string.
12157
12158 var newOverflow = (baseId & newOverflowBits).toString(32); // Now we can remove those bits from the base id.
12159
12160 var restOfBaseId = baseId >> numberOfOverflowBits;
12161 var restOfBaseLength = baseLength - numberOfOverflowBits; // Finally, encode the rest of the bits using the normal algorithm. Because
12162 // we made more room, this time it won't overflow.
12163
12164 var restOfLength = getBitLength(totalChildren) + restOfBaseLength;
12165 var restOfNewBits = slot << restOfBaseLength;
12166 var id = restOfNewBits | restOfBaseId;
12167 var overflow = newOverflow + baseOverflow;
12168 treeContextId = 1 << restOfLength | id;
12169 treeContextOverflow = overflow;
12170 } else {
12171 // Normal path
12172 var newBits = slot << baseLength;
12173
12174 var _id = newBits | baseId;
12175
12176 var _overflow = baseOverflow;
12177 treeContextId = 1 << length | _id;
12178 treeContextOverflow = _overflow;
12179 }
12180 }
12181 function pushMaterializedTreeId(workInProgress) {

Callers

nothing calls this directly

Calls 3

warnIfNotHydratingFunction · 0.70
getBitLengthFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…