Skip to content

Commit 03c94bf

Browse files
committed
Prevent unnecessary copying for legacy context as well
1 parent 01d0784 commit 03c94bf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/internals/context.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ let currentContextMap: ContextMap = {}
1515
let prevContextMap: void | ContextMap = undefined
1616
let prevContextEntry: void | ContextEntry = undefined
1717

18-
export const getCurrentContextMap = (): ContextMap => currentContextMap
18+
export const getCurrentContextMap = (): ContextMap =>
19+
Object.assign({}, currentContextMap)
1920
export const getCurrentContextStore = (): ContextStore =>
2021
new Map(currentContextStore)
2122

@@ -32,7 +33,7 @@ export const flushPrevContextStore = (): void | ContextEntry => {
3233
}
3334

3435
export const restoreContextMap = (prev: ContextMap) => {
35-
currentContextMap = prev
36+
Object.assign(currentContextMap, prev)
3637
}
3738

3839
export const restoreContextStore = (prev: ContextEntry) => {
@@ -50,8 +51,11 @@ export const setCurrentContextStore = (store: ContextStore) => {
5051
}
5152

5253
export const assignContextMap = (map: ContextMap) => {
53-
prevContextMap = currentContextMap
54-
currentContextMap = Object.assign({}, currentContextMap, map)
54+
prevContextMap = {}
55+
for (const name in map) {
56+
prevContextMap[name] = currentContextMap[name]
57+
currentContextMap[name] = map[name]
58+
}
5559
}
5660

5761
export const setContextValue = (context: AbstractContext, value: mixed) => {

0 commit comments

Comments
 (0)