Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.6k
Commit557d31e
py/objint: Try to convert big-int back to small-int after binary op.
Before this change, long/mpz ints propagated into all future calculations,even if their value could fit in a small-int object. With this change, theresult of a big-int binary op will now be converted to a small-int objectif the value fits in a small-int.For example, a relatively common operation like `x = a * b // c` wherea,b,c all small ints would always result in a long/mpz int, even if itdidn't need to, and then this would impact all future calculations withx.This adds +24 bytes on PYBV11 but avoids heap allocations and potentialsurprises (e.g. `big-big` is now a small `0`, and can safely be accessedwith MP_OBJ_SMALL_INT_VALUE).Performance tests are unchanged on PYBV10, except for `bm_pidigits.py`which makes heavy use of big-ints and gains about 8% in speed.Unix coverage tests have been updated to cover mpz code that is nowunreachable by normal Python code (removing the unreachable code would leadto some surprising gaps in the internal C functions and the functionalitymay be needed in the future, so it is kept because it has minimaloverhead).This work was funded through GitHub Sponsors.Signed-off-by: Jim Mussared <jim.mussared@gmail.com>1 parent0600e4f commit557d31e
File tree
6 files changed
+80
-15
lines changed- ports/unix
- py
- tests
- basics
- ports/unix
6 files changed
+80
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
454 | 455 | | |
455 | 456 | | |
456 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
457 | 465 | | |
458 | 466 | | |
459 | 467 | | |
| |||
470 | 478 | | |
471 | 479 | | |
472 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
473 | 484 | | |
474 | 485 | | |
475 | 486 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | 250 | | |
254 | 251 | | |
255 | 252 | | |
256 | 253 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | 254 | | |
263 | 255 | | |
264 | 256 | | |
265 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
266 | 262 | | |
267 | 263 | | |
268 | | - | |
| 264 | + | |
269 | 265 | | |
270 | 266 | | |
271 | 267 | | |
272 | 268 | | |
273 | 269 | | |
274 | 270 | | |
275 | 271 | | |
276 | | - | |
277 | | - | |
278 | | - | |
| 272 | + | |
279 | 273 | | |
280 | 274 | | |
281 | 275 | | |
282 | 276 | | |
283 | 277 | | |
284 | | - | |
285 | 278 | | |
286 | | - | |
| 279 | + | |
287 | 280 | | |
288 | | - | |
| 281 | + | |
289 | 282 | | |
290 | 283 | | |
291 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
315 | 323 | | |
316 | 324 | | |
317 | 325 | | |
| |||
425 | 433 | | |
426 | 434 | | |
427 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
428 | 440 | | |
429 | 441 | | |
430 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
0 commit comments
Comments
(0)