Skip to content

Commit

Permalink
refactor: switch memoization library
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfan committed Mar 17, 2021
1 parent d5b01f1 commit fc65f6a
Show file tree
Hide file tree
Showing 4 changed files with 747 additions and 801 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"dependencies": {
"@orioro/typing": "^4.4.0",
"lodash": "^4.17.20",
"memoizee": "^0.4.15"
"mem": "^8.0.0"
},
"config": {
"commitizen": {
Expand Down
9 changes: 6 additions & 3 deletions src/interpreter/asyncParamResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import memoize from 'memoizee/weak'
const mem = require('mem') // eslint-disable-line @typescript-eslint/no-var-requires

import {
ANY_TYPE,
Expand All @@ -23,7 +23,9 @@ import { _pseudoSymbol } from '../util/misc'

const _NOT_RESOLVED = _pseudoSymbol()

const _asyncParamResolver = memoize(
const _asyncParamResolverMemoCache = new WeakMap()

const _asyncParamResolver = mem(
(typeSpec: NonShorthandTypeSpec): ParamResolver => {
if (typeSpec.skipEvaluation) {
return (context, value) => Promise.resolve(value)
Expand Down Expand Up @@ -119,7 +121,8 @@ const _asyncParamResolver = memoize(
)
}
}
}
},
{ cache: _asyncParamResolverMemoCache }
)

/**
Expand Down
9 changes: 6 additions & 3 deletions src/interpreter/syncParamResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import memoize from 'memoizee/weak'
const mem = require('mem') // eslint-disable-line @typescript-eslint/no-var-requires

import {
ANY_TYPE,
Expand All @@ -22,7 +22,9 @@ import { _pseudoSymbol } from '../util/misc'

const _NOT_RESOLVED = _pseudoSymbol()

const _syncParamResolver = memoize(
const _syncParamResolverMemoCache = new WeakMap()

const _syncParamResolver = mem(
(typeSpec: NonShorthandTypeSpec): ParamResolver => {
if (typeSpec.skipEvaluation) {
return (context, value) => value
Expand Down Expand Up @@ -121,7 +123,8 @@ const _syncParamResolver = memoize(
}
}
}
}
},
{ cache: _syncParamResolverMemoCache }
)

/**
Expand Down
Loading

0 comments on commit fc65f6a

Please sign in to comment.