diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2023-02-13 18:34:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-13 18:34:41 +0100 |
commit | 2e644e845051703775b35b358eec5d3608a9465f (patch) | |
tree | f1b17f379cd4875a3f8e60a9d20f2354333ce4d5 /src/selector/createCache.js | |
parent | 7e7bd062070b3eca8ee047136ea8575fbed5d70f (diff) | |
download | jquery-2e644e845051703775b35b358eec5d3608a9465f.tar.gz jquery-2e644e845051703775b35b358eec5d3608a9465f.zip |
Selector: Backport jQuery selection context logic to selector-native
This makes:
```js
$div.find("div > *")
```
no longer matching children of `$div`.
Also, leading combinators now work, e.g.:
```js
$div.find( "> *" );
```
returns children of `$div`.
As a result of that, a number of tests are no longer skipped in the
`selector-native` mode.
Also, rename `rcombinators` to `rleadingCombinator`.
Fixes gh-5185
Closes gh-5186
Ref gh-5085
Diffstat (limited to 'src/selector/createCache.js')
-rw-r--r-- | src/selector/createCache.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/selector/createCache.js b/src/selector/createCache.js new file mode 100644 index 000000000..18e255d0f --- /dev/null +++ b/src/selector/createCache.js @@ -0,0 +1,26 @@ +import jQuery from "../core.js"; + +/** + * Create key-value caches of limited size + * @returns {function(string, object)} Returns the Object data after storing it on itself with + * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength) + * deleting the oldest entry + */ +function createCache() { + var keys = []; + + function cache( key, value ) { + + // Use (key + " ") to avoid collision with native prototype properties + // (see https://github.com/jquery/sizzle/issues/157) + if ( keys.push( key + " " ) > jQuery.expr.cacheLength ) { + + // Only keep the most recent entries + delete cache[ keys.shift() ]; + } + return ( cache[ key + " " ] = value ); + } + return cache; +} + +export default createCache; |