Don't repeatedly loop enums in enums.read
This commit is contained in:
parent
cf3c2790f2
commit
94b27c9a02
15
src/enums.js
15
src/enums.js
|
@ -2,6 +2,8 @@
|
||||||
* @module enums
|
* @module enums
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const byValue = Symbol('byValue');
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
/** Maps curve names under various standards to one
|
/** Maps curve names under various standards to one
|
||||||
|
@ -456,10 +458,15 @@ export default {
|
||||||
|
|
||||||
/** Converts from an integer to string. */
|
/** Converts from an integer to string. */
|
||||||
read: function(type, e) {
|
read: function(type, e) {
|
||||||
for (const i in type) {
|
if (!type[byValue]) {
|
||||||
if (type[i] === parseInt(e, 10)) {
|
type[byValue] = [];
|
||||||
return i;
|
Object.entries(type).forEach(([key, value]) => {
|
||||||
}
|
type[byValue][value] = key;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type[byValue][e] !== undefined) {
|
||||||
|
return type[byValue][e];
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Invalid enum value.');
|
throw new Error('Invalid enum value.');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user