mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-07 13:24:16 +02:00
Performance improvement
This commit is contained in:
parent
4371c5af95
commit
23b0f68954
1 changed files with 12 additions and 13 deletions
|
|
@ -810,25 +810,24 @@ export function sortBy(arr, fn) {
|
||||||
return arr.sort(cmp);
|
return arr.sort(cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllPropertyNames(obj, names = new Set()) {
|
||||||
|
if (!obj) return names;
|
||||||
|
|
||||||
|
for (const name of Object.getOwnPropertyNames(obj)) {
|
||||||
|
names.add(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getAllPropertyNames(Object.getPrototypeOf(obj), names);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a shallow copy including getters of the given object.
|
* Returns a shallow copy including getters of the given object.
|
||||||
* Generally used for expanding roll data without side effects
|
* Generally used for expanding roll data without side effects
|
||||||
*/
|
*/
|
||||||
export function shallowCopyWithGetters(obj) {
|
export function shallowCopyWithGetters(obj) {
|
||||||
function getAllPropertyDescriptors(obj) {
|
const props = getAllPropertyNames(obj);
|
||||||
if (!obj) {
|
|
||||||
return Object.create(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...getAllPropertyDescriptors(Object.getPrototypeOf(obj)),
|
|
||||||
...Object.getOwnPropertyDescriptors(obj)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = getAllPropertyDescriptors(obj);
|
|
||||||
const result = {};
|
const result = {};
|
||||||
for (const key of Object.keys(props)) {
|
for (const key of props) {
|
||||||
const value = obj[key];
|
const value = obj[key];
|
||||||
if (key !== '__proto__' && typeof value !== 'function') {
|
if (key !== '__proto__' && typeof value !== 'function') {
|
||||||
result[key] = obj[key];
|
result[key] = obj[key];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue