Cleanup unneeded codes regarding `unsafe` (#1188)
authorGanbarukamo41 <ganbarukamo@gmail.com>
Fri, 27 Dec 2019 15:38:19 +0000 (00:38 +0900)
committerJan Kotas <jkotas@microsoft.com>
Fri, 27 Dec 2019 15:38:19 +0000 (07:38 -0800)
* Remove incorrect comments

* Remove unnecessary `unsafe` keywords

src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextEncoder.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImpl.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextReaderImplAsync.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlTextWriter.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlUtf8RawTextWriter.cs
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/DtdParser.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/DtdParserAsync.cs
src/libraries/System.Private.Xml/src/System/Xml/ValidateNames.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlCharType.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs

index e7c99e1..912615c 100644 (file)
@@ -143,12 +143,9 @@ namespace System.Xml
             while (true)
             {
                 int startPos = i;
-                unsafe
+                while (i < endPos && _xmlCharType.IsAttributeValueChar(ch = array[i]))
                 {
-                    while (i < endPos && _xmlCharType.IsAttributeValueChar(ch = array[i]))
-                    {
-                        i++;
-                    }
+                    i++;
                 }
 
                 if (startPos < i)
@@ -272,13 +269,11 @@ namespace System.Xml
             char ch = (char)0;
             while (true)
             {
-                unsafe
+                while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
                 {
-                    while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
-                    {
-                        i++;
-                    }
+                    i++;
                 }
+
                 if (i == len)
                 {
                     // reached the end of the string -> write it whole out
@@ -387,12 +382,9 @@ namespace System.Xml
                 }
                 i++;
                 startPos = i;
-                unsafe
+                while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
                 {
-                    while (i < len && _xmlCharType.IsAttributeValueChar(ch = text[i]))
-                    {
-                        i++;
-                    }
+                    i++;
                 }
             }
         }
@@ -414,12 +406,9 @@ namespace System.Xml
 
             while (true)
             {
-                unsafe
+                while (i < len && (_xmlCharType.IsCharData((ch = text[i])) || ch < 0x20))
                 {
-                    while (i < len && (_xmlCharType.IsCharData((ch = text[i])) || ch < 0x20))
-                    {
-                        i++;
-                    }
+                    i++;
                 }
                 if (i == len)
                 {
index 11af001..491d76a 100644 (file)
@@ -3771,12 +3771,9 @@ namespace System.Xml
                 char[] chars;
             Continue:
                 chars = _ps.chars;
-                unsafe
+                while (_xmlCharType.IsAttributeValueChar(chars[pos]))
                 {
-                    while (_xmlCharType.IsAttributeValueChar(chars[pos]))
-                    {
-                        pos++;
-                    }
+                    pos++;
                 }
 
                 if (_ps.chars[pos] == quoteChar)
@@ -4325,44 +4322,38 @@ namespace System.Xml
         // case occurs (like end of buffer, invalid name char)
         ContinueStartName:
             // check element name start char
-            unsafe
+            if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
+            {
+                pos++;
+            }
+#if XML10_FIFTH_EDITION
+            else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
+            {
+                pos += 2;
+            }
+#endif
+            else
             {
-                if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
+                goto ParseQNameSlow;
+            }
+
+        ContinueName:
+            // parse element name
+            while (true)
+            {
+                if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
                 {
                     pos++;
                 }
 #if XML10_FIFTH_EDITION
-                else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
+                else if (pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
                 {
                     pos += 2;
                 }
 #endif
                 else
                 {
-                    goto ParseQNameSlow;
-                }
-            }
-
-        ContinueName:
-            unsafe
-            {
-                // parse element name
-                while (true)
-                {
-                    if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
-                    {
-                        pos++;
-                    }
-#if XML10_FIFTH_EDITION
-                    else if (pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
-                    {
-                        pos += 2;
-                    }
-#endif
-                    else
-                    {
-                        break;
-                    }
+                    break;
                 }
             }
 
@@ -4430,11 +4421,7 @@ namespace System.Xml
 
             char ch = chars[pos];
             // whitespace after element name -> there are probably some attributes
-            bool isWs;
-            unsafe
-            {
-                isWs = _xmlCharType.IsWhiteSpace(ch);
-            }
+            bool isWs = _xmlCharType.IsWhiteSpace(ch);
             if (isWs)
             {
                 _ps.charPos = pos;
@@ -4620,16 +4607,13 @@ namespace System.Xml
                     goto ReadData;
                 }
 
-                unsafe
-                {
-                    if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
+                if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
 #if XML10_FIFTH_EDITION
-                         || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
+                        || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
 #endif
-                        )
-                    {
-                        ThrowTagMismatch(startTagNode);
-                    }
+                    )
+                {
+                    ThrowTagMismatch(startTagNode);
                 }
 
                 // eat whitespace
@@ -4732,54 +4716,48 @@ namespace System.Xml
                 // eat whitespace
                 int lineNoDelta = 0;
                 char tmpch0;
-                unsafe
+                while (_xmlCharType.IsWhiteSpace(tmpch0 = chars[pos]))
                 {
-                    while (_xmlCharType.IsWhiteSpace(tmpch0 = chars[pos]))
+                    if (tmpch0 == (char)0xA)
                     {
-                        if (tmpch0 == (char)0xA)
+                        OnNewLine(pos + 1);
+                        lineNoDelta++;
+                    }
+                    else if (tmpch0 == (char)0xD)
+                    {
+                        if (chars[pos + 1] == (char)0xA)
+                        {
+                            OnNewLine(pos + 2);
+                            lineNoDelta++;
+                            pos++;
+                        }
+                        else if (pos + 1 != _ps.charsUsed)
                         {
                             OnNewLine(pos + 1);
                             lineNoDelta++;
                         }
-                        else if (tmpch0 == (char)0xD)
+                        else
                         {
-                            if (chars[pos + 1] == (char)0xA)
-                            {
-                                OnNewLine(pos + 2);
-                                lineNoDelta++;
-                                pos++;
-                            }
-                            else if (pos + 1 != _ps.charsUsed)
-                            {
-                                OnNewLine(pos + 1);
-                                lineNoDelta++;
-                            }
-                            else
-                            {
-                                _ps.charPos = pos;
-                                goto ReadData;
-                            }
+                            _ps.charPos = pos;
+                            goto ReadData;
                         }
-                        pos++;
                     }
+                    pos++;
                 }
 
                 char tmpch1;
                 int startNameCharSize = 0;
 
-                unsafe
+                if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
                 {
-                    if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
-                    {
-                        startNameCharSize = 1;
-                    }
+                    startNameCharSize = 1;
+                }
 #if XML10_FIFTH_EDITION
-                    else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1))
-                    {
-                        startNameCharSize = 2;
-                    }
-#endif
+                else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1))
+                {
+                    startNameCharSize = 2;
                 }
+#endif
 
                 if (startNameCharSize == 0)
                 {
@@ -4846,24 +4824,21 @@ namespace System.Xml
             ContinueParseName:
                 char tmpch2;
 
-                unsafe
+                while (true)
                 {
-                    while (true)
+                    if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
                     {
-                        if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
-                        {
-                            pos++;
-                        }
+                        pos++;
+                    }
 #if XML10_FIFTH_EDITION
-                        else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2))
-                        {
-                            pos += 2;
-                        }
+                    else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2))
+                    {
+                        pos += 2;
+                    }
 #endif
-                        else
-                        {
-                            break;
-                        }
+                    else
+                    {
+                        break;
                     }
                 }
 
@@ -4887,20 +4862,17 @@ namespace System.Xml
                         colonPos = pos;
                         pos++;
 
-                        unsafe
+                        if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
                         {
-                            if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
-                            {
-                                pos++;
-                                goto ContinueParseName;
-                            }
+                            pos++;
+                            goto ContinueParseName;
+                        }
 #if XML10_FIFTH_EDITION
-                            else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
-                                pos += 2;
-                                goto ContinueParseName;
-                            }
-#endif
+                        else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
+                            pos += 2;
+                            goto ContinueParseName;
                         }
+#endif
                         // else fallback to full name parsing routine
                         pos = ParseQName(out colonPos);
                         chars = _ps.chars;
@@ -4952,13 +4924,11 @@ namespace System.Xml
 
                 // parse attribute value
                 char tmpch3;
-                unsafe
+                while (_xmlCharType.IsAttributeValueChar(tmpch3 = chars[pos]))
                 {
-                    while (_xmlCharType.IsAttributeValueChar(tmpch3 = chars[pos]))
-                    {
-                        pos++;
-                    }
+                    pos++;
                 }
+
                 if (tmpch3 == quoteChar)
                 {
 #if DEBUG
@@ -5182,12 +5152,9 @@ namespace System.Xml
             while (true)
             {
                 // parse the rest of the attribute value
-                unsafe
+                while (_xmlCharType.IsAttributeValueChar(chars[pos]))
                 {
-                    while (_xmlCharType.IsAttributeValueChar(chars[pos]))
-                    {
-                        pos++;
-                    }
+                    pos++;
                 }
 
                 if (pos - _ps.charPos > 0)
@@ -5619,13 +5586,10 @@ namespace System.Xml
             while (true)
             {
                 // parse text content
-                unsafe
+                while (_xmlCharType.IsTextChar(c = chars[pos]))
                 {
-                    while (_xmlCharType.IsTextChar(c = chars[pos]))
-                    {
-                        orChars |= (int)c;
-                        pos++;
-                    }
+                    orChars |= (int)c;
+                    pos++;
                 }
 
                 switch (c)
@@ -6383,12 +6347,9 @@ namespace System.Xml
             while (true)
             {
                 char tmpch;
-                unsafe
+                while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != '?')
                 {
-                    while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != '?')
-                    {
-                        pos++;
-                    }
+                    pos++;
                 }
 
                 switch (chars[pos])
@@ -6589,12 +6550,9 @@ namespace System.Xml
             while (true)
             {
                 char tmpch;
-                unsafe
+                while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != stopChar)
                 {
-                    while (_xmlCharType.IsTextChar(tmpch = chars[pos]) && tmpch != stopChar)
-                    {
-                        pos++;
-                    }
+                    pos++;
                 }
 
                 // possibly end of comment or cdata section
@@ -6939,12 +6897,9 @@ namespace System.Xml
             {
                 char ch;
 
-                unsafe
+                while (_xmlCharType.IsAttributeValueChar(ch = chars[pos]) && chars[pos] != stopChar && ch != '-' && ch != '?')
                 {
-                    while (_xmlCharType.IsAttributeValueChar(ch = chars[pos]) && chars[pos] != stopChar && ch != '-' && ch != '?')
-                    {
-                        pos++;
-                    }
+                    pos++;
                 }
 
                 // closing stopChar outside of literal and ignore/include sections -> save value & return
@@ -7593,54 +7548,48 @@ namespace System.Xml
             char[] chars = _ps.chars;
 
             // start name char
-            unsafe
+            if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
             {
-                if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
-                {
-                    pos++;
-                }
+                pos++;
+            }
 #if XML10_FIFTH_EDITION
-                else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
-                {
-                    pos += 2;
-                }
+            else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos]))
+            {
+                pos += 2;
+            }
 #endif
-                else
+            else
+            {
+                if (pos + 1 >= _ps.charsUsed)
                 {
-                    if (pos + 1 >= _ps.charsUsed)
-                    {
-                        if (ReadDataInName(ref pos))
-                        {
-                            goto ContinueStartName;
-                        }
-                        Throw(pos, SR.Xml_UnexpectedEOF, "Name");
-                    }
-                    if (chars[pos] != ':' || _supportNamespaces)
+                    if (ReadDataInName(ref pos))
                     {
-                        Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
+                        goto ContinueStartName;
                     }
+                    Throw(pos, SR.Xml_UnexpectedEOF, "Name");
+                }
+                if (chars[pos] != ':' || _supportNamespaces)
+                {
+                    Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
                 }
             }
 
         ContinueName:
             // parse name
-            unsafe
+            while (true)
             {
-                while (true)
+                if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
                 {
-                    if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
-                    {
-                        pos++;
-                    }
+                    pos++;
+                }
 #if XML10_FIFTH_EDITION
-                    else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
-                        pos += 2;
-                    }
+                else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar( chars[pos + 1], chars[pos] ) ) {
+                    pos += 2;
+                }
 #endif
-                    else
-                    {
-                        break;
-                    }
+                else
+                {
+                    break;
                 }
             }
 
@@ -8358,21 +8307,18 @@ namespace System.Xml
                     _incReadLineInfo.Set(_ps.LineNo, _ps.LinePos);
 
                     char c;
-                    unsafe
+                    if (_incReadState == IncrementalReadState.Attributes)
                     {
-                        if (_incReadState == IncrementalReadState.Attributes)
+                        while (_xmlCharType.IsAttributeValueChar(c = chars[pos]) && c != '/')
                         {
-                            while (_xmlCharType.IsAttributeValueChar(c = chars[pos]) && c != '/')
-                            {
-                                pos++;
-                            }
+                            pos++;
                         }
-                        else
+                    }
+                    else
+                    {
+                        while (_xmlCharType.IsAttributeValueChar(c = chars[pos]))
                         {
-                            while (_xmlCharType.IsAttributeValueChar(c = chars[pos]))
-                            {
-                                pos++;
-                            }
+                            pos++;
                         }
                     }
 
@@ -8665,11 +8611,8 @@ namespace System.Xml
 
             while (true)
             {
-                unsafe
-                {
-                    while (_xmlCharType.IsAttributeValueChar(chars[pos]))
-                        pos++;
-                }
+                while (_xmlCharType.IsAttributeValueChar(chars[pos]))
+                    pos++;
 
                 switch (chars[pos])
                 {
index 030481a..a6e8135 100644 (file)
@@ -1950,44 +1950,38 @@ namespace System.Xml
         // case occurs (like end of buffer, invalid name char)
         ContinueStartName:
             // check element name start char
-            unsafe
+            if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
             {
-                if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
-                {
-                    pos++;
-                }
+                pos++;
+            }
 
 #if XML10_FIFTH_EDITION
-                else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
-                    pos += 2;
-                }
+            else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+                pos += 2;
+            }
 #endif
-                else
-                {
-                    goto ParseQNameSlow;
-                }
+            else
+            {
+                goto ParseQNameSlow;
             }
 
         ContinueName:
-            unsafe
+            // parse element name
+            while (true)
             {
-                // parse element name
-                while (true)
+                if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
                 {
-                    if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
-                    {
-                        pos++;
-                    }
+                    pos++;
+                }
 
 #if XML10_FIFTH_EDITION
-                    else if ( pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
-                        pos += 2;
-                    }
+                else if ( pos < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+                    pos += 2;
+                }
 #endif
-                    else
-                    {
-                        break;
-                    }
+                else
+                {
+                    break;
                 }
             }
 
@@ -2298,16 +2292,13 @@ namespace System.Xml
 
                 bool tagMismatch = false;
 
-                unsafe
-                {
-                    if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
+                if (_xmlCharType.IsNCNameSingleChar(chars[pos]) || (chars[pos] == ':')
 #if XML10_FIFTH_EDITION
-                         || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
+                        || xmlCharType.IsNCNameHighSurrogateChar(chars[pos])
 #endif
 )
-                    {
-                        tagMismatch = true;
-                    }
+                {
+                    tagMismatch = true;
                 }
 
                 if (tagMismatch)
@@ -2460,18 +2451,15 @@ namespace System.Xml
                 char tmpch1;
                 int startNameCharSize = 0;
 
-                unsafe
+                if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
                 {
-                    if (_xmlCharType.IsStartNCNameSingleChar(tmpch1 = chars[pos]))
-                    {
-                        startNameCharSize = 1;
-                    }
+                    startNameCharSize = 1;
+                }
 #if XML10_FIFTH_EDITION
-                    else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1 )) {
-                        startNameCharSize = 2;
-                    }
-#endif
+                else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch1 )) {
+                    startNameCharSize = 2;
                 }
+#endif
 
                 if (startNameCharSize == 0)
                 {
@@ -2538,23 +2526,20 @@ namespace System.Xml
             ContinueParseName:
                 char tmpch2;
 
-                unsafe
+                while (true)
                 {
-                    while (true)
+                    if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
                     {
-                        if (_xmlCharType.IsNCNameSingleChar(tmpch2 = chars[pos]))
-                        {
-                            pos++;
-                        }
+                        pos++;
+                    }
 #if XML10_FIFTH_EDITION
-                        else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2)) {
-                            pos += 2;
-                        }
+                    else if (pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], tmpch2)) {
+                        pos += 2;
+                    }
 #endif
-                        else
-                        {
-                            break;
-                        }
+                    else
+                    {
+                        break;
                     }
                 }
 
@@ -2578,20 +2563,17 @@ namespace System.Xml
                         colonPos = pos;
                         pos++;
 
-                        unsafe
+                        if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
                         {
-                            if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
-                            {
-                                pos++;
-                                goto ContinueParseName;
-                            }
+                            pos++;
+                            goto ContinueParseName;
+                        }
 #if XML10_FIFTH_EDITION
-                            else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
-                                pos += 2;
-                                goto ContinueParseName;
-                            }
-#endif
+                        else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+                            pos += 2;
+                            goto ContinueParseName;
                         }
+#endif
 
                         // else fallback to full name parsing routine
 
@@ -5136,65 +5118,52 @@ namespace System.Xml
         ContinueStartName:
             char[] chars = _ps.chars;
 
-            //a tmp flag, used to avoid await keyword in unsafe context.
-            bool awaitReadDataInNameAsync = false;
             // start name char
-            unsafe
+            if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
             {
-                if (_xmlCharType.IsStartNCNameSingleChar(chars[pos]))
-                {
-                    pos++;
-                }
+                pos++;
+            }
 
 #if XML10_FIFTH_EDITION
-                else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
-                    pos += 2;
-                }
+            else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+                pos += 2;
+            }
 #endif
-                else
+            else
+            {
+                if (pos + 1 >= _ps.charsUsed)
                 {
-                    if (pos + 1 >= _ps.charsUsed)
-                    {
-                        awaitReadDataInNameAsync = true;
-                    }
-                    else if (chars[pos] != ':' || _supportNamespaces)
+                    var tuple_27 = await ReadDataInNameAsync(pos).ConfigureAwait(false);
+                    pos = tuple_27.Item1;
+
+                    if (tuple_27.Item2)
                     {
-                        Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
+                        goto ContinueStartName;
                     }
+                    Throw(pos, SR.Xml_UnexpectedEOF, "Name");
                 }
-            }
-
-            if (awaitReadDataInNameAsync)
-            {
-                var tuple_27 = await ReadDataInNameAsync(pos).ConfigureAwait(false);
-                pos = tuple_27.Item1;
-
-                if (tuple_27.Item2)
+                else if (chars[pos] != ':' || _supportNamespaces)
                 {
-                    goto ContinueStartName;
+                    Throw(pos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(chars, _ps.charsUsed, pos));
                 }
-                Throw(pos, SR.Xml_UnexpectedEOF, "Name");
             }
 
         ContinueName:
             // parse name
-            unsafe
+            while (true)
             {
-                while (true)
+                if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
                 {
-                    if (_xmlCharType.IsNCNameSingleChar(chars[pos]))
-                    {
-                        pos++;
-                    }
+                    pos++;
+                }
 #if XML10_FIFTH_EDITION
-                    else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
-                        pos += 2;
-                    }
+                else if ( pos + 1 < ps.charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[pos + 1], chars[pos])) {
+                    pos += 2;
+                }
 #endif
-                    else
-                    {
-                        break;
-                    }
+                else
+                {
+                    break;
                 }
             }
 
index d40ef70..555afa9 100644 (file)
@@ -1655,7 +1655,7 @@ namespace System.Xml
         // Unfortunatelly the names of elements and attributes are not validated by the XmlTextWriter.
         // Also this method does not check wheather the character after ':' is a valid start name character. It accepts
         // all valid name characters at that position. This can't be changed because of backwards compatibility.
-        private unsafe void ValidateName(string name, bool isNCName)
+        private void ValidateName(string name, bool isNCName)
         {
             if (name == null || name.Length == 0)
             {
index 648bc4d..d989bf2 100644 (file)
@@ -1708,7 +1708,7 @@ namespace System.Xml
             return pDst + 3;
         }
 
-        protected unsafe void ValidateContentChars(string chars, string propertyName, bool allowOnlyWhitespace)
+        protected void ValidateContentChars(string chars, string propertyName, bool allowOnlyWhitespace)
         {
             if (allowOnlyWhitespace)
             {
index 1a1a951..f3742b4 100644 (file)
@@ -2122,7 +2122,7 @@ namespace System.Xml
             return s;
         }
 
-        private unsafe void CheckNCName(string ncname)
+        private void CheckNCName(string ncname)
         {
             Debug.Assert(ncname != null && ncname.Length > 0);
 
index 749e9a9..b0b13b1 100644 (file)
@@ -3007,53 +3007,47 @@ namespace System.Xml
 
             while (true)
             {
-                unsafe
+                if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
                 {
-                    if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
-                    {
-                        _curPos++;
-                    }
+                    _curPos++;
+                }
 #if XML10_FIFTH_EDITION
-                    else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
-                        curPos += 2;
-                    }
+                else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
+                    curPos += 2;
+                }
 #endif
-                    else
+                else
+                {
+                    if (_curPos + 1 >= _charsUsed)
                     {
-                        if (_curPos + 1 >= _charsUsed)
+                        if (ReadDataInName())
                         {
-                            if (ReadDataInName())
-                            {
-                                continue;
-                            }
-                            Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
-                        }
-                        else
-                        {
-                            Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
+                            continue;
                         }
+                        Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
+                    }
+                    else
+                    {
+                        Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
                     }
                 }
 
             ContinueName:
 
-                unsafe
+                while (true)
                 {
-                    while (true)
+                    if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
                     {
-                        if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
-                        {
-                            _curPos++;
-                        }
+                        _curPos++;
+                    }
 #if XML10_FIFTH_EDITION
-                        else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
-                            curPos += 2;
-                        }
+                    else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
+                        curPos += 2;
+                    }
 #endif
-                        else
-                        {
-                            break;
-                        }
+                    else
+                    {
+                        break;
                     }
                 }
 
@@ -3113,23 +3107,20 @@ namespace System.Xml
 
             while (true)
             {
-                unsafe
+                while (true)
                 {
-                    while (true)
+                    if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
                     {
-                        if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
-                        {
-                            _curPos++;
-                        }
+                        _curPos++;
+                    }
 #if XML10_FIFTH_EDITION
-                        else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
-                            curPos += 2;
-                        }
+                    else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
+                        curPos += 2;
+                    }
 #endif
-                        else
-                        {
-                            break;
-                        }
+                    else
+                    {
+                        break;
                     }
                 }
 
index 19c6c4f..50e2da7 100644 (file)
@@ -2413,59 +2413,46 @@ namespace System.Xml
 
             while (true)
             {
-                //a tmp flag, used to avoid await keyword in unsafe context.
-                bool awaitReadDataInNameAsync = false;
-                unsafe
+                if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
                 {
-                    if (_xmlCharType.IsStartNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
-                    {
-                        _curPos++;
-                    }
+                    _curPos++;
+                }
 #if XML10_FIFTH_EDITION
-                    else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
-                        curPos += 2;
-                    }
+                else if ( curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos+1], chars[curPos])) {
+                    curPos += 2;
+                }
 #endif
-                    else
+                else
+                {
+                    if (_curPos + 1 >= _charsUsed)
                     {
-                        if (_curPos + 1 >= _charsUsed)
-                        {
-                            awaitReadDataInNameAsync = true;
-                        }
-                        else
+                        if (await ReadDataInNameAsync().ConfigureAwait(false))
                         {
-                            Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
+                            continue;
                         }
+                        Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
                     }
-                }
-
-                if (awaitReadDataInNameAsync)
-                {
-                    if (await ReadDataInNameAsync().ConfigureAwait(false))
+                    else
                     {
-                        continue;
+                        Throw(_curPos, SR.Xml_BadStartNameChar, XmlException.BuildCharExceptionArgs(_chars, _charsUsed, _curPos));
                     }
-                    Throw(_curPos, SR.Xml_UnexpectedEOF, "Name");
                 }
 
             ContinueName:
-                unsafe
+                while (true)
                 {
-                    while (true)
+                    if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
                     {
-                        if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]))
-                        {
-                            _curPos++;
-                        }
+                        _curPos++;
+                    }
 #if XML10_FIFTH_EDITION
-                        else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
-                            curPos += 2;
-                        }
+                    else if ( curPos + 1 < charsUsed && xmlCharType.IsNameSurrogateChar(chars[curPos + 1], chars[curPos]) ) {
+                        curPos += 2;
+                    }
 #endif
-                        else
-                        {
-                            break;
-                        }
+                    else
+                    {
+                        break;
                     }
                 }
 
@@ -2525,23 +2512,20 @@ namespace System.Xml
 
             while (true)
             {
-                unsafe
+                while (true)
                 {
-                    while (true)
+                    if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
                     {
-                        if (_xmlCharType.IsNCNameSingleChar(_chars[_curPos]) || _chars[_curPos] == ':')
-                        {
-                            _curPos++;
-                        }
+                        _curPos++;
+                    }
 #if XML10_FIFTH_EDITION
-                        else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
-                            curPos += 2;
-                        }
+                    else if (curPos + 1 < charsUsed && xmlCharType.IsNCNameSurrogateChar(chars[curPos + 1], chars[curPos])) {
+                        curPos += 2;
+                    }
 #endif
-                        else
-                        {
-                            break;
-                        }
+                    else
+                    {
+                        break;
                     }
                 }
 
index 6cc5f38..e751bc1 100644 (file)
@@ -36,7 +36,7 @@ namespace System.Xml
         /// Quits parsing when an invalid Nmtoken char is reached or the end of string is reached.
         /// Returns the number of valid Nmtoken chars that were parsed.
         /// </summary>
-        internal static unsafe int ParseNmtoken(string s, int offset)
+        internal static int ParseNmtoken(string s, int offset)
         {
             Debug.Assert(s != null && offset <= s.Length);
 
@@ -72,7 +72,7 @@ namespace System.Xml
         /// Quits parsing when an invalid Nmtoken char is reached or the end of string is reached.
         /// Returns the number of valid Nmtoken chars that were parsed.
         /// </summary>
-        internal static unsafe int ParseNmtokenNoNamespaces(string s, int offset)
+        internal static int ParseNmtokenNoNamespaces(string s, int offset)
         {
             Debug.Assert(s != null && offset <= s.Length);
 
@@ -116,7 +116,7 @@ namespace System.Xml
         /// Quits parsing when an invalid Name char is reached or the end of string is reached.
         /// Returns the number of valid Name chars that were parsed.
         /// </summary>
-        internal static unsafe int ParseNameNoNamespaces(string s, int offset)
+        internal static int ParseNameNoNamespaces(string s, int offset)
         {
             Debug.Assert(s != null && offset <= s.Length);
 
@@ -178,7 +178,7 @@ namespace System.Xml
         /// Quits parsing when an invalid NCName char is reached or the end of string is reached.
         /// Returns the number of valid NCName chars that were parsed.
         /// </summary>
-        internal static unsafe int ParseNCName(string s, int offset)
+        internal static int ParseNCName(string s, int offset)
         {
             Debug.Assert(s != null && offset <= s.Length);
 
index 2c917c1..16af340 100644 (file)
@@ -97,19 +97,16 @@ namespace System.Xml
             }
         }
 
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         public bool IsWhiteSpace(char ch)
         {
             return (charProperties[ch] & fWhitespace) != 0;
         }
 
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         public bool IsNCNameSingleChar(char ch)
         {
             return (charProperties[ch] & fNCNameSC) != 0;
         }
 
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         public bool IsStartNCNameSingleChar(char ch)
         {
             return (charProperties[ch] & fNCStartNameSC) != 0;
@@ -120,7 +117,6 @@ namespace System.Xml
             return IsNCNameSingleChar(ch) || ch == ':';
         }
 
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         public bool IsCharData(char ch)
         {
             return (charProperties[ch] & fCharData) != 0;
@@ -137,28 +133,23 @@ namespace System.Xml
         }
 
         // TextChar = CharData - { 0xA, 0xD, '<', '&', ']' }
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         internal bool IsTextChar(char ch)
         {
             return (charProperties[ch] & fText) != 0;
         }
 
         // AttrValueChar = CharData - { 0xA, 0xD, 0x9, '<', '>', '&', '\'', '"' }
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         internal bool IsAttributeValueChar(char ch)
         {
             return (charProperties[ch] & fAttrValue) != 0;
         }
 
         // XML 1.0 Fourth Edition definitions
-        //
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         public bool IsLetter(char ch)
         {
             return (charProperties[ch] & fLetter) != 0;
         }
 
-        // NOTE: This method will not be inlined (because it uses byte* charProperties)
         // This method uses the XML 4th edition name character ranges
         public bool IsNCNameCharXml4e(char ch)
         {
index 0be6622..8187578 100644 (file)
@@ -380,7 +380,7 @@ namespace System.Xml
             return null;
         }
 
-        internal static unsafe string VerifyQName(string name, ExceptionType exceptionType)
+        internal static string VerifyQName(string name, ExceptionType exceptionType)
         {
             if (name == null || name.Length == 0)
             {
@@ -579,7 +579,7 @@ namespace System.Xml
 
         // Start name character types - as defined in Namespaces XML 1.0 spec (second edition) production [6] NCNameStartChar
         //                              combined with the production [4] NameStartChar of XML 1.0 spec
-        public static unsafe bool IsStartNCNameChar(char ch)
+        public static bool IsStartNCNameChar(char ch)
         {
             return s_xmlCharType.IsStartNCNameSingleChar(ch);
         }
@@ -593,7 +593,7 @@ namespace System.Xml
 
         // Name character types - as defined in Namespaces XML 1.0 spec (second edition) production [6] NCNameStartChar
         //                        combined with the production [4] NameChar of XML 1.0 spec
-        public static unsafe bool IsNCNameChar(char ch)
+        public static bool IsNCNameChar(char ch)
         {
             return s_xmlCharType.IsNCNameSingleChar(ch);
         }
@@ -606,7 +606,7 @@ namespace System.Xml
 #endif
 
         // Valid XML character - as defined in XML 1.0 spec (fifth edition) production [2] Char
-        public static unsafe bool IsXmlChar(char ch)
+        public static bool IsXmlChar(char ch)
         {
             return s_xmlCharType.IsCharData(ch);
         }
@@ -623,7 +623,7 @@ namespace System.Xml
         }
 
         // Valid Xml whitespace - as defined in XML 1.0 spec (fifth edition) production [3] S
-        public static unsafe bool IsWhitespaceChar(char ch)
+        public static bool IsWhitespaceChar(char ch)
         {
             return s_xmlCharType.IsWhiteSpace(ch);
         }
@@ -1435,7 +1435,7 @@ namespace System.Xml
             VerifyCharData(data, exceptionType, exceptionType);
         }
 
-        internal static unsafe void VerifyCharData(string data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType)
+        internal static void VerifyCharData(string data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType)
         {
             if (data == null || data.Length == 0)
             {
@@ -1477,7 +1477,7 @@ namespace System.Xml
             }
         }
 
-        internal static unsafe void VerifyCharData(char[] data, int offset, int len, ExceptionType exceptionType)
+        internal static void VerifyCharData(char[] data, int offset, int len, ExceptionType exceptionType)
         {
             if (data == null || len == 0)
             {