Commit c9d9df5
authored
Rollup merge of rust-lang#59262 - timvermeulen:iterator_cmp_dedup, r=scottmcm
Remove duplicated code from Iterator::{ne, lt, le, gt, ge}
This PR delegates `Iterator::ne` to `Iterator::eq` and `Iterator::{lt, le, gt, ge}` to `Iterator::partial_cmp`.
Oddly enough, this change actually simplifies the generated assembly [in some cases](https://rust.godbolt.org/z/riBtNe), although I don't understand assembly well enough to see if the longer assembly is doing something clever.
I also added two extremely simple benchmarks:
```
// before
test iter::bench_lt ... bench: 98,404 ns/iter (+/- 21,008)
test iter::bench_partial_cmp ... bench: 62,437 ns/iter (+/- 5,009)
// after
test iter::bench_lt ... bench: 61,757 ns/iter (+/- 8,770)
test iter::bench_partial_cmp ... bench: 62,151 ns/iter (+/- 13,753)
```
I have no idea why the current `lt`/`le`/`gt`/`ge` implementations don't seem to be compiled optimally, but simply having them call `partial_cmp` seems to be an improvement.
See rust-lang#44729 for a previous discussion.2 files changed
+24
-98
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2435 | 2435 | | |
2436 | 2436 | | |
2437 | 2437 | | |
2438 | | - | |
| 2438 | + | |
2439 | 2439 | | |
2440 | 2440 | | |
2441 | 2441 | | |
2442 | 2442 | | |
2443 | | - | |
2444 | | - | |
2445 | | - | |
2446 | | - | |
2447 | | - | |
2448 | | - | |
2449 | | - | |
2450 | | - | |
2451 | | - | |
2452 | | - | |
2453 | | - | |
2454 | | - | |
2455 | | - | |
2456 | | - | |
2457 | | - | |
| 2443 | + | |
2458 | 2444 | | |
2459 | 2445 | | |
2460 | 2446 | | |
2461 | 2447 | | |
2462 | 2448 | | |
2463 | | - | |
| 2449 | + | |
2464 | 2450 | | |
2465 | 2451 | | |
2466 | 2452 | | |
2467 | 2453 | | |
2468 | | - | |
2469 | | - | |
2470 | | - | |
2471 | | - | |
2472 | | - | |
2473 | | - | |
2474 | | - | |
2475 | | - | |
2476 | | - | |
2477 | | - | |
2478 | | - | |
2479 | | - | |
2480 | | - | |
2481 | | - | |
2482 | | - | |
2483 | | - | |
2484 | | - | |
2485 | | - | |
2486 | | - | |
2487 | | - | |
| 2454 | + | |
2488 | 2455 | | |
2489 | 2456 | | |
2490 | 2457 | | |
2491 | 2458 | | |
2492 | 2459 | | |
2493 | | - | |
| 2460 | + | |
2494 | 2461 | | |
2495 | 2462 | | |
2496 | 2463 | | |
2497 | 2464 | | |
2498 | | - | |
2499 | | - | |
2500 | | - | |
2501 | | - | |
2502 | | - | |
2503 | | - | |
2504 | | - | |
2505 | | - | |
2506 | | - | |
2507 | | - | |
2508 | | - | |
2509 | | - | |
2510 | | - | |
2511 | | - | |
2512 | | - | |
2513 | | - | |
2514 | | - | |
2515 | | - | |
2516 | | - | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
2517 | 2468 | | |
2518 | 2469 | | |
2519 | 2470 | | |
2520 | 2471 | | |
2521 | 2472 | | |
2522 | 2473 | | |
2523 | | - | |
| 2474 | + | |
2524 | 2475 | | |
2525 | 2476 | | |
2526 | 2477 | | |
2527 | 2478 | | |
2528 | | - | |
2529 | | - | |
2530 | | - | |
2531 | | - | |
2532 | | - | |
2533 | | - | |
2534 | | - | |
2535 | | - | |
2536 | | - | |
2537 | | - | |
2538 | | - | |
2539 | | - | |
2540 | | - | |
2541 | | - | |
2542 | | - | |
2543 | | - | |
2544 | | - | |
2545 | | - | |
2546 | | - | |
2547 | | - | |
| 2479 | + | |
2548 | 2480 | | |
2549 | 2481 | | |
2550 | 2482 | | |
2551 | 2483 | | |
2552 | 2484 | | |
2553 | | - | |
| 2485 | + | |
2554 | 2486 | | |
2555 | 2487 | | |
2556 | 2488 | | |
2557 | 2489 | | |
2558 | | - | |
2559 | | - | |
2560 | | - | |
2561 | | - | |
2562 | | - | |
2563 | | - | |
2564 | | - | |
2565 | | - | |
2566 | | - | |
2567 | | - | |
2568 | | - | |
2569 | | - | |
2570 | | - | |
2571 | | - | |
2572 | | - | |
2573 | | - | |
2574 | | - | |
2575 | | - | |
2576 | | - | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
2577 | 2493 | | |
2578 | 2494 | | |
2579 | 2495 | | |
| |||
0 commit comments