<body><div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000;text-align: left" dir="ltr">
                                        Thanks Nicolas! Also for this elaborate commit message. :-)<div><br></div><div>Best,</div><div>Marcel</div><div class="mb_sig"></div><blockquote class='history_container' type='cite' style='border-left-style:solid;border-width:1px; margin-top:20px; margin-left:0px;padding-left:10px;'>
                        <p style='color: #AAAAAA; margin-top: 10px;'>Am 28.11.2021 23:16:00 schrieb Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com>:</p><div style='font-family:Arial,Helvetica,sans-serif'>
<div dir="ltr"><div>Note: there might be a minor 2 to 3% penalty for small fractions like 5/3</div><div>because this change introduces a super send in the path to Fraction class>>numerator:denominator:</div><div>but IMO, it's not worth the code duplication.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le dim. 28 nov. 2021 à 22:44, <<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Nicolas Cellier uploaded a new version of Kernel to project The Trunk:<br>
<a href="http://source.squeak.org/trunk/Kernel-nice.1428.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/trunk/Kernel-nice.1428.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Kernel-nice.1428<br>
Author: nice<br>
Time: 28 November 2021, 10:44:44.154815 pm<br>
UUID: a8a214a1-7879-4782-8dd7-910f183fda65<br>
Ancestors: Kernel-nice.1427<br>
<br>
Simplify code for integer division, and marginally fast up some edge case like (SmallInteger / LargeInteger)<br>
<br>
Discussion:<br>
Integer was trying to handle case of exact division (Integer / Integer) by performing a quorem operation (digitDiv:neg:), in the hope that avoiding the creation of an unecessary Fraction intermediate would fast things up.<br>
<br>
But it appears that digitDiv:neg: does no good nowadays.<br>
- primitive 10 for SmallInteger/SmallInteger case,<br>
- primitive 30 for Integer/Integer case (up to 64 bits)<br>
already handle exact division (their sole purpose if they exist!).<br>
<br>
If 10 & 30 are not implemented (they are optional), probably we do not care that much about such micro optimization anyway.<br>
<br>
in mixed cases:<br>
- (SmallInteger / LargeInteger), division cannot be exact - except for 0 receiver, so we're just wasting time<br>
<br>
Anyway, digitDiv:neg: creates a LargeInteger object for each SmallInteger receiver/argument, and an Array for the resulting quotient and remainder, so in term of creating intermediate objects, it's not much better.<br>
It is also pure waste of time if division is inexact - and division tend to not be cheap for LargeInteger.<br>
Also, gcd: algorithm used in Fraction>>#reduced performs well enough in the case of exact division.<br>
<br>
While at it, only handle zero divide in Integer/Integer case.<br>
Let further dispatching handle the case for mixed Integer/Number arithmetic (Integer shall mind its own business).<br>
Note that Fraction>>#setNumerator:denominator: already signal the ZeroDivide, but would not resume: correctly (we send #reduced to the result, which assumes that it is a Fraction)<br>
<br>
Warning: benchmarking and understanding the marginal fast-up is not easy, because we have:<br>
- a special bytecode for division<br>
- special primitive for 64 bits integer range<br>
- jit for some of those primitives<br>
that's many cases.<br>
<br>
Thanks to <a href="https://github.com/pharo-project/pharo/pull/10385" rel="noreferrer" target="_blank">https://github.com/pharo-project/pharo/pull/10385</a> for asking.<br>
<br>
=============== Diff against Kernel-nice.1427 ===============<br>
<br>
Item was changed:<br>
  ----- Method: Integer>>/ (in category 'arithmetic') -----<br>
  / aNumber<br>
        "Refer to the comment in Number / "<br>
-       | quoRem |<br>
        aNumber isInteger ifTrue:<br>
+               [aNumber isZero<br>
+                       ifTrue: [^(ZeroDivide dividend: self) signal].<br>
+               ^ (Fraction numerator: self denominator: aNumber) reduced].<br>
-               [quoRem := self divideByInteger: aNumber.<br>
-               (quoRem at: 2) = 0<br>
-                       ifTrue: [^ (quoRem at: 1) normalize]<br>
-                       ifFalse: [^ (Fraction numerator: self denominator: aNumber) reduced]].<br>
        ^ aNumber adaptToInteger: self andSend: #/!<br>
<br>
Item was changed:<br>
  ----- Method: SmallInteger>>/ (in category 'arithmetic') -----<br>
  / aNumber <br>
        "Primitive. This primitive (for /) divides the receiver by the argument<br>
        and returns the result if the division is exact. Fail if the result is not a<br>
        whole integer. Fail if the argument is 0 or is not a SmallInteger. Optional.<br>
        No Lookup. See Object documentation whatIsAPrimitive."<br>
<br>
        <primitive: 10><br>
+       ^super / aNumber!<br>
-       aNumber isZero ifTrue: [^(ZeroDivide dividend: self) signal].<br>
-       ^(aNumber isMemberOf: SmallInteger)<br>
-               ifTrue: [(Fraction numerator: self denominator: aNumber) reduced]<br>
-               ifFalse: [super / aNumber]!<br>
<br>
<br>
</blockquote></div>
</div></blockquote>
                                        </div></body>