You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- General simplifications.
- Add code to Length setter to avoid possible infinite capacity grow (following full .NET fix).
- Changed to expression properties.
- Remove names from exceptions.
@@ -35,67 +39,77 @@ public sealed class StringBuilder
35
39
/// Gets the maximum capacity of this instance.
36
40
/// </summary>
37
41
/// <value>The maximum number of characters this instance can hold.</value>
38
-
publicintMaxCapacity
39
-
{
40
-
get
41
-
{
42
-
return_maxCapacity;
43
-
}
44
-
}
42
+
publicintMaxCapacity=>_maxCapacity;
45
43
46
44
/// <summary>
47
45
/// Gets or sets the character at the specified character position in this instance.
48
46
/// </summary>
49
47
/// <param name="index">The position of the character.</param>
50
48
/// <returns>The Unicode character at position index.</returns>
49
+
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is outside the bounds of this instance while getting a character.</exception>"
50
+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is outside the bounds of this instance while setting a character.</exception>"
51
51
publiccharthis[intindex]
52
52
{
53
53
get
54
54
{
55
-
varchunkPrevious=this;
55
+
StringBuilderchunk=this;
56
+
56
57
while(true)
57
58
{
58
-
varnum=index-chunkPrevious._chunkOffset;
59
-
if(num>=0)
59
+
intindexInBlock=index-chunk._chunkOffset;
60
+
61
+
if(indexInBlock>=0)
60
62
{
61
-
if(num>=chunkPrevious._chunkLength)
63
+
if(indexInBlock>=chunk._chunkLength)
62
64
{
63
65
#pragma warning disable S112// General exceptions should never be thrown
64
66
thrownewIndexOutOfRangeException();
65
67
#pragma warning restore S112// General exceptions should never be thrown
66
68
}
67
-
returnchunkPrevious._chunkChars[num];
69
+
70
+
returnchunk._chunkChars[indexInBlock];
68
71
}
69
-
chunkPrevious=chunkPrevious._chunkPrevious;
70
-
if(chunkPrevious==null)
72
+
73
+
chunk=chunk._chunkPrevious;
74
+
75
+
if(chunk==null)
71
76
{
72
77
#pragma warning disable S112// General exceptions should never be thrown
73
78
thrownewIndexOutOfRangeException();
74
79
#pragma warning restore S112// General exceptions should never be thrown
75
80
}
76
81
}
77
82
}
83
+
78
84
set
79
85
{
80
-
varchunkPrevious=this;
81
-
Label_0002:
82
-
varnum=index-chunkPrevious._chunkOffset;
83
-
if(num>=0)
86
+
StringBuilderchunk=this;
87
+
88
+
while(true)
84
89
{
85
-
if(num>=chunkPrevious._chunkLength)
90
+
intindexInBlock=index-chunk._chunkOffset;
91
+
92
+
if(indexInBlock>=0)
86
93
{
87
-
thrownewArgumentOutOfRangeException("index");
94
+
if(indexInBlock>=chunk._chunkLength)
95
+
{
96
+
#pragma warning disable S3928// Parameter names used into ArgumentException constructors should match an existing one
97
+
thrownewArgumentOutOfRangeException();
98
+
#pragma warning restore S3928// OK to use in .NET nanoFramework context
99
+
}
100
+
101
+
chunk._chunkChars[indexInBlock]=value;
102
+
return;
88
103
}
89
-
chunkPrevious._chunkChars[num]=value;
90
-
}
91
-
else
92
-
{
93
-
chunkPrevious=chunkPrevious._chunkPrevious;
94
-
if(chunkPrevious==null)
104
+
105
+
chunk=chunk._chunkPrevious;
106
+
107
+
if(chunk==null)
95
108
{
96
-
thrownewArgumentOutOfRangeException("index");
109
+
#pragma warning disable S3928// Parameter names used into ArgumentException constructors should match an existing one
110
+
thrownewArgumentOutOfRangeException();
111
+
#pragma warning restore S3928// OK to use in .NET nanoFramework context
97
112
}
98
-
gotoLabel_0002;
99
113
}
100
114
}
101
115
}
@@ -106,72 +120,101 @@ public char this[int index]
106
120
/// <value>
107
121
/// The maximum number of characters that can be contained in the memory allocated by the current instance. Its value can range from Length to MaxCapacity.
/// <exception cref="ArgumentOutOfRangeException">If <see cref="Length"/> is set to a value that is less than zero or greater than <see cref="MaxCapacity"/>.</exception>
0 commit comments