kopia lustrzana https://github.com/badgen/badgen
Optimize performance
rodzic
a8cb2f32af
commit
b7c0ad38c0
|
@ -10,9 +10,15 @@ function calcWidth (charWidthTable) {
|
|||
if (typeof text !== 'string') {
|
||||
return 0
|
||||
} else {
|
||||
return Array.from(text).reduce((total, curr) => {
|
||||
return total + (widthTable[curr.charCodeAt()] || widthTable[64]) // "@"
|
||||
}, 0)
|
||||
let total = 0
|
||||
let i = text.length
|
||||
let charCode = 0
|
||||
while (i--) {
|
||||
charCode = text[i].charCodeAt()
|
||||
total += widthTable[charCode < 127 ? charCode : 64] // "@" for overflows
|
||||
}
|
||||
console.log(total)
|
||||
return total
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue