diff --git a/src/mscorlib/src/System/Globalization/IdnMapping.cs b/src/mscorlib/src/System/Globalization/IdnMapping.cs index cbc0e7988835..7881ac47410f 100644 --- a/src/mscorlib/src/System/Globalization/IdnMapping.cs +++ b/src/mscorlib/src/System/Globalization/IdnMapping.cs @@ -710,8 +710,10 @@ static String punycode_encode(String unicode) k >= bias + tmax ? tmax : k - bias; if (q < t) break; Contract.Assert(punycodeBase != t, "[IdnMapping.punycode_encode]Expected punycodeBase (36) to be != t"); - output.Append(encode_digit(t + (q - t) % (punycodeBase - t))); - q = (q - t) / (punycodeBase - t); + + int mod; + q = Math.DivRem(q - t, punycodeBase - t, out mod); + output.Append(encode_digit(t + mod)); } output.Append(encode_digit(q)); diff --git a/src/mscorlib/src/System/Math.cs b/src/mscorlib/src/System/Math.cs index cf2b0ee15c31..9ff0a9f6c898 100644 --- a/src/mscorlib/src/System/Math.cs +++ b/src/mscorlib/src/System/Math.cs @@ -726,13 +726,21 @@ public static long BigMul(int a, int b) { } public static int DivRem(int a, int b, out int result) { - result = a%b; - return a/b; + // TODO https://github.com/dotnet/coreclr/issues/3439: + // Restore to using % and / when the JIT is able to eliminate one of the idivs. + // In the meantime, a * and - is measurably faster than an extra /. + int div = a / b; + result = a - (div * b); + return div; } public static long DivRem(long a, long b, out long result) { - result = a%b; - return a/b; + // TODO https://github.com/dotnet/coreclr/issues/3439: + // Restore to using % and / when the JIT is able to eliminate one of the idivs. + // In the meantime, a * and - is measurably faster than an extra /. + long div = a / b; + result = a - (div * b); + return div; } } }