Skip to content

Commit

Permalink
Code golf
Browse files Browse the repository at this point in the history
  • Loading branch information
realyze committed Feb 19, 2024
1 parent b015bc9 commit 8ce69b6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/mobx/src/core/derivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ export function checkIfStateReadsAreAllowed(observable: IObservable) {
export function trackDerivedFunction<T>(derivation: IDerivation, f: () => T, context: any) {
const prevAllowStateReads = allowStateReadsStart(true)
changeDependenciesStateTo0(derivation)
// pre allocate array allocation + 20% extra room for variation in deps
// array will be trimmed by bindDependencies
derivation.newObserving_ = new Array(Math.ceil(derivation.observing_.length * 1.2))
// Preallocate array; will be trimmed by bindDependencies.
derivation.newObserving_ = new Array(
derivation.observing_.length
? Math.ceil(derivation.observing_.length * 1.2) // 20% extra room for variation in deps
: 100 // Establishing initial dependencies, preallocate constant space.
)
derivation.unboundDepsCount_ = 0
derivation.runId_ = ++globalState.runId
const prevTracking = globalState.trackingDerivation
Expand Down

0 comments on commit 8ce69b6

Please sign in to comment.