@@ -112,19 +112,7 @@ public partial class JsonPackageSpecReader
112112 internal static PackageSpec GetPackageSpecUtf8JsonStreamReader ( Stream stream , string name , string packageSpecPath , string snapshotValue )
113113 {
114114 var reader = new Utf8JsonStreamReader ( stream ) ;
115- PackageSpec packageSpec ;
116- packageSpec = GetPackageSpec ( ref reader , name , packageSpecPath , snapshotValue ) ;
117-
118- if ( ! string . IsNullOrEmpty ( name ) )
119- {
120- packageSpec . Name = name ;
121- if ( ! string . IsNullOrEmpty ( packageSpecPath ) )
122- {
123- packageSpec . FilePath = Path . GetFullPath ( packageSpecPath ) ;
124-
125- }
126- }
127- return packageSpec ;
115+ return GetPackageSpec ( ref reader , name , packageSpecPath , snapshotValue ) ;
128116 }
129117
130118 internal static PackageSpec GetPackageSpec ( ref Utf8JsonStreamReader jsonReader , string name , string packageSpecPath , string snapshotValue )
@@ -277,9 +265,10 @@ internal static PackageSpec GetPackageSpec(ref Utf8JsonStreamReader jsonReader,
277265
278266 internal static void ReadCentralTransitiveDependencyGroup (
279267 ref Utf8JsonStreamReader jsonReader ,
280- IList < LibraryDependency > results ,
268+ out IList < LibraryDependency > results ,
281269 string packageSpecPath )
282270 {
271+ results = null ;
283272 if ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . StartObject )
284273 {
285274 while ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . PropertyName )
@@ -295,10 +284,12 @@ internal static void ReadCentralTransitiveDependencyGroup(
295284 if ( jsonReader . Read ( ) )
296285 {
297286 var libraryDependency = ReadLibraryDependency ( ref jsonReader , packageSpecPath , libraryName ) ;
287+ results ??= [ ] ;
298288 results . Add ( libraryDependency ) ;
299289 }
300290 }
301291 }
292+ results ??= Array . Empty < LibraryDependency > ( ) ;
302293 }
303294
304295 private static LibraryDependency ReadLibraryDependency ( ref Utf8JsonStreamReader jsonReader , string packageSpecPath , string libraryName )
@@ -733,10 +724,15 @@ private static void ReadDownloadDependencies(
733724 packageSpecPath ) ;
734725 }
735726
736- string [ ] versions = versionValue . Split ( VersionSeparators , StringSplitOptions . RemoveEmptyEntries ) ;
727+ var versions = new LazyStringSplit ( versionValue , VersionSeparator ) ;
737728
738729 foreach ( string singleVersionValue in versions )
739730 {
731+ if ( string . IsNullOrEmpty ( singleVersionValue ) )
732+ {
733+ continue ;
734+ }
735+
740736 try
741737 {
742738 VersionRange version = VersionRange . Parse ( singleVersionValue ) ;
@@ -938,7 +934,7 @@ private static void ReadMSBuildMetadata(ref Utf8JsonStreamReader jsonReader, Pac
938934 RestoreLockProperties restoreLockProperties = null ;
939935 var skipContentFileWrite = false ;
940936 List < PackageSource > sources = null ;
941- List < ProjectRestoreMetadataFrameworkInfo > targetFrameworks = null ;
937+ IList < ProjectRestoreMetadataFrameworkInfo > targetFrameworks = null ;
942938 var validateRuntimeAssets = false ;
943939 WarningProperties warningProperties = null ;
944940 RestoreAuditProperties auditProperties = null ;
@@ -1294,7 +1290,7 @@ private static void ReadPackageTypes(PackageSpec packageSpec, ref Utf8JsonStream
12941290 packageTypes = new [ ] { packageType } ;
12951291 break ;
12961292 case JsonTokenType . StartArray :
1297- var types = new List < PackageType > ( ) ;
1293+ List < PackageType > types = null ;
12981294
12991295 while ( jsonReader . Read ( ) && jsonReader . TokenType != JsonTokenType . EndArray )
13001296 {
@@ -1309,8 +1305,10 @@ private static void ReadPackageTypes(PackageSpec packageSpec, ref Utf8JsonStream
13091305 }
13101306
13111307 packageType = CreatePackageType ( ref jsonReader ) ;
1308+ types ??= [ ] ;
13121309 types . Add ( packageType ) ;
13131310 }
1311+
13141312 packageTypes = types ;
13151313 break ;
13161314 case JsonTokenType . Null :
@@ -1541,14 +1539,14 @@ private static RuntimeDescription ReadRuntimeDescription(ref Utf8JsonStreamReade
15411539
15421540 private static List < RuntimeDescription > ReadRuntimes ( ref Utf8JsonStreamReader jsonReader )
15431541 {
1544- var runtimeDescriptions = new List < RuntimeDescription > ( ) ;
1542+ List < RuntimeDescription > runtimeDescriptions = null ;
15451543
15461544 if ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . StartObject )
15471545 {
15481546 while ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . PropertyName )
15491547 {
15501548 RuntimeDescription runtimeDescription = ReadRuntimeDescription ( ref jsonReader , jsonReader . GetString ( ) ) ;
1551-
1549+ runtimeDescriptions ??= [ ] ;
15521550 runtimeDescriptions . Add ( runtimeDescription ) ;
15531551 }
15541552 }
@@ -1572,14 +1570,15 @@ private static void ReadScripts(ref Utf8JsonStreamReader jsonReader, PackageSpec
15721570 }
15731571 else if ( jsonReader . TokenType == JsonTokenType . StartArray )
15741572 {
1575- var list = new List < string > ( ) ;
1573+ IList < string > list = null ;
15761574
15771575 while ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . String )
15781576 {
1577+ list ??= [ ] ;
15791578 list . Add ( jsonReader . GetString ( ) ) ;
15801579 }
15811580
1582- packageSpec . Scripts [ propertyName ] = list ;
1581+ packageSpec . Scripts [ propertyName ] = list ?? Enumerable . Empty < string > ( ) ;
15831582 }
15841583 else
15851584 {
@@ -1594,15 +1593,15 @@ private static void ReadScripts(ref Utf8JsonStreamReader jsonReader, PackageSpec
15941593
15951594 private static List < CompatibilityProfile > ReadSupports ( ref Utf8JsonStreamReader jsonReader )
15961595 {
1597- var compatibilityProfiles = new List < CompatibilityProfile > ( ) ;
1596+ List < CompatibilityProfile > compatibilityProfiles = null ;
15981597
15991598 if ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . StartObject )
16001599 {
16011600 while ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . PropertyName )
16021601 {
16031602 var propertyName = jsonReader . GetString ( ) ;
16041603 CompatibilityProfile compatibilityProfile = ReadCompatibilityProfile ( ref jsonReader , propertyName ) ;
1605-
1604+ compatibilityProfiles ??= [ ] ;
16061605 compatibilityProfiles . Add ( compatibilityProfile ) ;
16071606 }
16081607 }
@@ -1640,7 +1639,7 @@ private static LibraryDependencyTarget ReadTarget(
16401639
16411640 private static List < ProjectRestoreMetadataFrameworkInfo > ReadTargetFrameworks ( ref Utf8JsonStreamReader jsonReader )
16421641 {
1643- var targetFrameworks = new List < ProjectRestoreMetadataFrameworkInfo > ( ) ;
1642+ List < ProjectRestoreMetadataFrameworkInfo > targetFrameworks = null ;
16441643
16451644 if ( jsonReader . Read ( ) && jsonReader . TokenType == JsonTokenType . StartObject )
16461645 {
@@ -1723,7 +1722,7 @@ private static List<ProjectRestoreMetadataFrameworkInfo> ReadTargetFrameworks(re
17231722 jsonReader . Skip ( ) ;
17241723 }
17251724 }
1726-
1725+ targetFrameworks ??= [ ] ;
17271726 targetFrameworks . Add ( frameworkGroup ) ;
17281727 }
17291728 }
0 commit comments