]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Optimize has_intersection func
authorSemyon Pupkov <mail@semyonpupkov.com>
Sat, 11 May 2024 12:41:06 +0000 (08:41 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Sat, 11 May 2024 12:41:06 +0000 (08:41 -0400)
commit5b43687da6820884c75531e89d6347bf285a3b2c
tree7878b2276f51072638b1576042ff93a026f733f8
parent93cfb49572ac56bc320a09b82285bf8ef8cdff57
Optimize has_intersection func

<!-- Provide a general summary of your proposed changes in the Title field above -->

Optimize `has_intersection` function.  It uses in few places, but even so it might be optimized. New version:
1. Does not allocate new set
2. A bit of performance speedup
```
from sqlalchemy import util

import timeit
import functools

a = {1, 2, 3}
b = [2, 3, 4]

t1 = timeit.Timer(functools.partial(util.has_intersection, a, b))
t2 = timeit.Timer(functools.partial(util.has_intersection2, a, b))

print("old", t1.timeit())
print("new", t2.timeit())

old 0.37196154199773446
new 0.29704541599494405

old 0.37331208398973104
new 0.29647241700149607
```

### Description
<!-- Describe your changes in detail -->

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [x] A documentation / typographical / small typing error fix
- Good to go, no issue or tests are needed
- [ ] A short code fix
- please include the issue number, and create an issue if none exists, which
  must include a complete example of the issue.  one line code fixes without an
  issue and demonstration will not be accepted.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
- please include the issue number, and create an issue if none exists, which must
  include a complete example of how the feature would look.
- Please include: `Fixes: #<issue number>` in the commit message
- please include tests.

**Have a nice day!**

Closes: #11378
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11378
Pull-request-sha: 258bf1af7c73c83502eb49240a996f5846c6a0a9

Change-Id: Ic1ec1448641304eba4751f55f1e3c2b217f7f352
lib/sqlalchemy/util/_collections.py