cache functions per V8 polymorphic cache rules

This commit is contained in:
davidmarkclements 2018-07-06 16:07:15 +02:00
Родитель 0f5d17b37f
Коммит 9e9b813629
1 изменённых файлов: 20 добавлений и 1 удалений

Просмотреть файл

@ -57,6 +57,25 @@ function getLevelVal () {
return this[levelValSym]
}
const loggingMethods = {
[levels.fatal]: {method: genLog(levels.fatal), count: 0},
[levels.error]: {method: genLog(levels.error), count: 0},
[levels.warn]: {method: genLog(levels.warn), count: 0},
[levels.info]: {method: genLog(levels.info), count: 0},
[levels.debug]: {method: genLog(levels.debug), count: 0},
[levels.trace]: {method: genLog(levels.trace), count: 0}
}
function getLoggingMethod (value) {
if (!(value in loggingMethods)) {
loggingMethods[value] = {method: genLog(value), count: 0}
return loggingMethods[value].method
}
loggingMethods[value].count = (loggingMethods[value].count + 1) % 4
if (loggingMethods[value].count === 0) loggingMethods[value].method = genLog(value)
return loggingMethods[value].method
}
function setLevelVal (num) {
if (typeof num === 'string') return this[setLevelSym](num)
@ -79,7 +98,7 @@ function setLevelVal (num) {
this[key] = noop
continue
}
this[key] = genLog(values[key])
this[key] = getLoggingMethod(values[key])
}
}