WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-34Lines changed: 14 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ const obj = { a: 1, b: 2 };
21
21
constcount=Object.keys(obj).length;
22
22
```
23
23
24
-
However, this approach creates unnecessary memory overhead and garbage collection pressure, as an intermediate array is allocated solely for counting properties. Highly-used runtimes, frameworks, and libraries (e.g., Node.js, React, Lodash, Angular) frequently utilize `Object.keys(obj).length`, compounding performance issues across applications.
24
+
However, this approach creates unnecessary memory overhead and garbage collection pressure, as an intermediate array is allocated solely for counting properties. Highly-used runtimes, frameworks, and libraries (e.g., Node.js, React, Lodash, Angular, Storybook, Excalidraw, VS Code, Svelte, Next.js, three.js, Puppeteer, Tailwind, ...) frequently utilize `Object.keys(obj).length`, compounding performance issues across applications.
25
25
26
26
For instance, React often counts props or state keys:
27
27
@@ -239,33 +239,7 @@ The native implementation should strictly avoid creating intermediate arrays or
239
239
- If the property meets all criteria, increment the counter.
When the `propertyCount` method is called, the following steps are taken:
245
-
246
-
**This is work in progress! The Algorithm is not yet fully defined.**
247
-
248
-
1. If Type(_target_) is not Object, throw a TypeError exception.
249
-
2. If _options_ is undefined, let _options_ be an empty Object.
250
-
3. Let _keyTypes_ be ? Get(_options_, "keyTypes").
251
-
4. If _keyTypes_ is undefined, set _keyTypes_ to the array `['index', 'nonIndexString']`.
252
-
5. Else, perform the following:
253
-
1. If Type(_keyTypes_) is not Object, throw a TypeError exception.
254
-
2. Set _keyTypes_ to an internal List whose elements are the String values of the elements of _keyTypes_.
255
-
3. If _keyTypes_ contains any value other than "index", "nonIndexString", or "symbol", throw a TypeError exception.
256
-
1. Let _enumerable_ be ? Get(_options_, "enumerable").
257
-
2. If _enumerable_ is undefined, set _enumerable_ to true.
258
-
3. Else if _enumerable_ is not one of true, false, or "all", throw a TypeError exception.
259
-
4. Let _count_ be 0.
260
-
5. Let _ownKeys_ be the List of own property keys of _target_, in the order returned by OrdinaryOwnPropertyKeys(_target_). (Note: No intermediate array should be allocated.)
261
-
6. For each element _key_ of _ownKeys_, perform the following steps:
262
-
1. Let _desc_ be ? OrdinaryGetOwnProperty(_target_, _key_).
263
-
2. If _enumerable_ is not 'all'
264
-
i. If _enumerable_ is unequal to _desc_.[[Enumerable]], continue to the next _key_.
265
-
3. If Type(_key_) is Symbol and "symbol" is present in _keyTypes_, increment _count_ by 1.
266
-
4. Else if Type(_key_) is array index and "index" is present in _keyTypes_, increment _count_ by 1.
267
-
5. Else if "nonIndexString" is present in _keyTypes_, increment _count_ by 1
268
-
7. Return _count_.
242
+
See the [spec proposal](./spec.emu) for details.
269
243
270
244
## Alternatives Considered
271
245
@@ -291,8 +265,16 @@ Frequent patterns in widely-used JavaScript runtimes, frameworks, and libraries
<p>When the `Object.propertyCount` method is called, the following steps are taken:</p>
15
15
<emu-alg>
16
-
1. Let _proposal_ be *undefined*.
17
-
1. If IsAccepted(_proposal_) is *true*, then
18
-
1. Let _stage_ be *0*<sub>ℤ</sub>.
19
-
1. Else,
20
-
1. Let _stage_ be *-1*<sub>ℤ</sub>.
21
-
1. Return ? ToString(_stage_).
16
+
1. If _target_ is not an Object, throw a TypeError exception.
17
+
1. Let _resolvedOptions_ be ? GetOptionsObject(_options_).
18
+
1. Let _keyTypes_ be ? Get(_resolvedOptions_, "keyTypes").
19
+
1. If _keyTypes_ is undefined, then
20
+
1. Set _keyTypes_ to the array `['index', 'nonIndexString']`.
21
+
1. Else, perform the following,
22
+
1. If _keyTypes_ is not an Object, throw a TypeError exception.
23
+
1. Set _keyTypes_ to an internal List whose elements are the String values of the elements of _keyTypes_.
24
+
1. If _keyTypes_ contains any value other than "index", "nonIndexString", or "symbol", throw a TypeError exception.
25
+
1. Let _enumerable_ be ? Get(_resolvedOptions_, "enumerable").
26
+
1. If _enumerable_ is undefined, set _enumerable_ to true.
27
+
1. Else if _enumerable_ is not one of true, false, or "all", throw a TypeError exception.
28
+
1. Let _count_ be 0.
29
+
1. Let _ownKeys_ be the List of own property keys of _target_, in the order returned by OrdinaryOwnPropertyKeys(_target_). (Note: No intermediate array should be allocated.)
30
+
1. For each element _key_ of _ownKeys_, perform the following steps, do
31
+
1. Let _desc_ be OrdinaryGetOwnProperty(_target_, _key_).
32
+
1. If _enumerable_ is not 'all', then
33
+
1. If _enumerable_ is unequal to _desc_.[[Enumerable]], continue to the next _key_.
34
+
1. If _key_ is Symbol and "symbol" is present in _keyTypes_, increment _count_ by 1.
35
+
1. Else if _key_ is an array index and "index" is present in _keyTypes_, increment _count_ by 1.
36
+
1. Else if "nonIndexString" is present in _keyTypes_, increment _count_ by 1.
0 commit comments