@@ -1053,30 +1053,42 @@ private void CreateThisFromUri(Uri otherUri)
1053
1053
{
1054
1054
DebugAssertInCtor ( ) ;
1055
1055
1056
- // Clone the other URI but develop own UriInfo member
1057
- _info = null ! ;
1058
-
1059
1056
_flags = otherUri . _flags ;
1060
- if ( InFact ( Flags . MinimalUriInfoSet ) )
1057
+
1058
+ if ( InFact ( Flags . AllUriInfoSet ) )
1059
+ {
1060
+ // We can share it now without mutation concern, for since AllUriInfoSet it is immutable.
1061
+ _info = otherUri . _info ;
1062
+ }
1063
+ else
1061
1064
{
1062
- _flags &= ~ ( Flags . MinimalUriInfoSet | Flags . AllUriInfoSet | Flags . IndexMask ) ;
1063
- // Port / Path offset
1064
- int portIndex = otherUri . _info . Offset . Path ;
1065
- if ( InFact ( Flags . NotDefaultPort ) )
1065
+ Debug . Assert ( ! InFact ( Flags . HasUnicode ) || otherUri . IsNotAbsoluteUri ) ;
1066
+ // Clone the other URI but develop own UriInfo member
1067
+ // We cannot just reference otherUri._info as this UriInfo will be mutated later
1068
+ // which could be happening concurrently and in a not thread safe manner.
1069
+ _info = null ! ;
1070
+
1071
+ if ( InFact ( Flags . MinimalUriInfoSet ) )
1066
1072
{
1067
- // Find the start of the port. Account for non-canonical ports like :00123
1068
- while ( otherUri . _string [ portIndex ] != ':' && portIndex > otherUri . _info . Offset . Host )
1073
+ _flags &= ~ ( Flags . MinimalUriInfoSet | Flags . AllUriInfoSet | Flags . IndexMask ) ;
1074
+ // Port / Path offset
1075
+ int portIndex = otherUri . _info . Offset . Path ;
1076
+ if ( InFact ( Flags . NotDefaultPort ) )
1069
1077
{
1070
- portIndex -- ;
1071
- }
1072
- if ( otherUri . _string [ portIndex ] != ':' )
1073
- {
1074
- // Something wrong with the NotDefaultPort flag. Reset to path index
1075
- Debug . Fail ( "Uri failed to locate custom port at index: " + portIndex ) ;
1076
- portIndex = otherUri . _info . Offset . Path ;
1078
+ // Find the start of the port. Account for non-canonical ports like :00123
1079
+ while ( otherUri . _string [ portIndex ] != ':' && portIndex > otherUri . _info . Offset . Host )
1080
+ {
1081
+ portIndex -- ;
1082
+ }
1083
+ if ( otherUri . _string [ portIndex ] != ':' )
1084
+ {
1085
+ // Something wrong with the NotDefaultPort flag. Reset to path index
1086
+ Debug . Fail ( "Uri failed to locate custom port at index: " + portIndex ) ;
1087
+ portIndex = otherUri . _info . Offset . Path ;
1088
+ }
1077
1089
}
1090
+ _flags |= ( Flags ) portIndex ; // Port or path
1078
1091
}
1079
- _flags |= ( Flags ) portIndex ; // Port or path
1080
1092
}
1081
1093
1082
1094
_syntax = otherUri . _syntax ;
0 commit comments