Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
/coreclrPublic archive

Commit09039ea

Browse files
committed
Use Math.DivRem in more places throughout mscorlib
1 parentbd1f21d commit09039ea

File tree

14 files changed

+55
-37
lines changed

14 files changed

+55
-37
lines changed

‎src/mscorlib/src/System/Collections/BitArray.cs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ public bool Get(int index) {
194194
thrownewArgumentOutOfRangeException(nameof(index),Environment.GetResourceString("ArgumentOutOfRange_Index"));
195195
}
196196
Contract.EndContractBlock();
197-
198-
return(m_array[index/32]&(1<<(index%32)))!=0;
197+
198+
intmod;
199+
intdiv=Math.DivRem(index,32,outmod);
200+
return(m_array[div]&(1<<mod))!=0;
199201
}
200202

201203
/*=========================================================================
@@ -209,11 +211,13 @@ public void Set(int index, bool value) {
209211
thrownewArgumentOutOfRangeException(nameof(index),Environment.GetResourceString("ArgumentOutOfRange_Index"));
210212
}
211213
Contract.EndContractBlock();
212-
214+
215+
intmod;
216+
intdiv=Math.DivRem(index,32,outmod);
213217
if(value){
214-
m_array[index/32]|=(1<<(index%32));
218+
m_array[div]|=(1<<mod);
215219
}else{
216-
m_array[index/32]&=~(1<<(index%32));
220+
m_array[div]&=~(1<<mod);
217221
}
218222

219223
_version++;

‎src/mscorlib/src/System/DateTime.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,9 @@ public DateTime AddMonths(int months) {
415415
intd=GetDatePart(DatePartDay);
416416
inti=m-1+months;
417417
if(i>=0){
418-
m=i%12+1;
419-
y=y+i/12;
418+
intmod;
419+
y=y+Math.DivRem(i,12,outmod);
420+
m=mod+1;
420421
}
421422
else{
422423
m=12+(i+1)%12;

‎src/mscorlib/src/System/Globalization/Calendar.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,9 @@ public virtual int ToFourDigitYear(int year) {
820820
}
821821
Contract.EndContractBlock();
822822
if(year<100){
823-
return((TwoDigitYearMax/100-(year>TwoDigitYearMax%100?1:0))*100+year);
823+
intmod;
824+
intdiv=Math.DivRem(TwoDigitYearMax,100,outmod);
825+
return((div-(year>mod?1:0))*100+year);
824826
}
825827
// If the year value is above 100, just return the year value. Don't have to do
826828
// the TwoDigitYearMax comparison.

‎src/mscorlib/src/System/Globalization/DateTimeFormat.cs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ internal unsafe static void FormatDigits(StringBuilder outputBuffer, int value,
190190
char*p=buffer+16;
191191
intn=value;
192192
do{
193-
*--p=(char)(n%10+'0');
194-
n/=10;
193+
intmod;
194+
n=Math.DivRem(n,10,outmod);
195+
*--p=(char)(mod+'0');
195196
}while((n!=0)&&(p>buffer));
196197

197198
intdigits=(int)(buffer+16-p);
@@ -1051,8 +1052,9 @@ internal static void AppendNumber(StringBuilder builder, long val, int digits)
10511052
intindex=1;
10521053
while(val>0&&index<=digits)
10531054
{
1054-
builder[builder.Length-index]=(char)('0'+(val%10));
1055-
val=val/10;
1055+
longmod;
1056+
val=Math.DivRem(val,10,outmod);
1057+
builder[builder.Length-index]=(char)('0'+mod);
10561058
index++;
10571059
}
10581060

‎src/mscorlib/src/System/Globalization/DateTimeParse.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,7 @@ private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result) {
538538
}
539539
elseif(length==3||length==4){
540540
// Parsing "+800" or "+0800"
541-
hourOffset=value/100;
542-
minuteOffset=value%100;
541+
hourOffset=Math.DivRem(value,100,outminuteOffset);
543542
str.ConsumeSubString(sub);
544543
}
545544
else{

‎src/mscorlib/src/System/Globalization/GregorianCalendar.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,9 @@ public override DateTime AddMonths(DateTime time, int months)
299299
inti=m-1+months;
300300
if(i>=0)
301301
{
302-
m=i%12+1;
303-
y=y+i/12;
302+
intmod;
303+
y=y+Math.DivRem(i,12,outmod);
304+
m=mod+1;
304305
}
305306
else
306307
{

‎src/mscorlib/src/System/Globalization/GregorianCalendarHelper.cs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ public DateTime AddMonths(DateTime time, int months)
362362
inti=m-1+months;
363363
if(i>=0)
364364
{
365-
m=i%12+1;
366-
y=y+i/12;
365+
intmod;
366+
y=y+Math.DivRem(i,12,outmod);
367+
m=mod+1;
367368
}
368369
else
369370
{
@@ -614,7 +615,9 @@ public int ToFourDigitYear(int year, int twoDigitYearMax) {
614615

615616
if(year<100){
616617
inty=year%100;
617-
return((twoDigitYearMax/100-(y>twoDigitYearMax%100?1:0))*100+y);
618+
intmod;
619+
intdiv=Math.DivRem(twoDigitYearMax,100,outmod);
620+
return((div-(y>mod?1:0))*100+y);
618621
}
619622

620623
if(year<m_minYear||year>m_maxYear){

‎src/mscorlib/src/System/Globalization/HijriCalendar.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,9 @@ public override DateTime AddMonths(DateTime time, int months) {
479479
intd=GetDatePart(time.Ticks,DatePartDay);
480480
inti=m-1+months;
481481
if(i>=0){
482-
m=i%12+1;
483-
y=y+i/12;
482+
intmod;
483+
y=y+Math.DivRem(i,12,outmod);
484+
m=mod+1;
484485
}else{
485486
m=12+(i+1)%12;
486487
y=y+(i-11)/12;

‎src/mscorlib/src/System/Globalization/IdnMapping.cs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,10 @@ static String punycode_encode(String unicode)
710710
k>=bias+tmax?tmax:k-bias;
711711
if(q<t)break;
712712
Contract.Assert(punycodeBase!=t,"[IdnMapping.punycode_encode]Expected punycodeBase (36) to be != t");
713-
output.Append(encode_digit(t+(q-t)%(punycodeBase-t)));
714-
q=(q-t)/(punycodeBase-t);
713+
714+
intmod;
715+
q=Math.DivRem(q-t,punycodeBase-t,outmod);
716+
output.Append(encode_digit(t+mod));
715717
}
716718

717719
output.Append(encode_digit(q));

‎src/mscorlib/src/System/Globalization/JulianCalendar.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ public override DateTime AddMonths(DateTime time, int months)
243243
intd=GetDatePart(time.Ticks,DatePartDay);
244244
inti=m-1+months;
245245
if(i>=0){
246-
m=i%12+1;
247-
y=y+i/12;
246+
intmod;
247+
y=y+Math.DivRem(i,12,outmod);
248+
m=mod+1;
248249
}
249250
else{
250251
m=12+(i+1)%12;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp