-
Notifications
You must be signed in to change notification settings - Fork 735
System.Text.Json Migration - Adding code to parse the Project.Assets.Json file using STJ. #5558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jgonz120
merged 43 commits into
dev-jgonz120-FeatureBranch-Stj-Migration
from
dev-FeatureBranch-jgonz120-Stj-LockfileFormat-Migration
Jan 26, 2024
Merged
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a57aabf
Copied initial files over and addressred some PR comments
jgonz120 05ed3db
Test updates
jgonz120 c285f0f
optimized string split
jgonz120 c06e3f5
cleanup
jgonz120 ef90a51
switch to stream
jgonz120 4c31cbf
fix typo
jgonz120 b787826
fix typo
jgonz120 c627b25
create static json reader state
jgonz120 ef35381
typo
jgonz120 084986d
typo
jgonz120 5850754
added lazy string split
jgonz120 014739f
using
jgonz120 d28a482
Update unit tests
jgonz120 c9cb53f
unit tests
jgonz120 d083e23
fix references
jgonz120 0b22126
Fix typo
jgonz120 e81974f
Added test for invalid logs
jgonz120 d2cc5d6
removed extra name assignment from package spec reader
jgonz120 2de68c4
use array empty
jgonz120 79e2b71
move public method up
jgonz120 ccd6fe1
remove uneeded string list
jgonz120 8d719c6
use false string
jgonz120 212b7bd
add is final block to test
jgonz120 b5a82d7
rename test
jgonz120 82363ee
style
jgonz120 0cc4e51
style
jgonz120 c525dc8
add tests for validating empty streams on creationg of utf8jsonstream…
jgonz120 4e5112a
Added test and implemented string split in two
jgonz120 2398980
fix validation for lazy string split
jgonz120 1693913
reduce methods in LikeFileFormat
jgonz120 e0ef66d
set the list values with the results directly
jgonz120 b4d0169
store environment variable to avoid calling GetEnvironmentVariable se…
jgonz120 f060670
switch to splitintwo
jgonz120 4602b44
Update conditional for framework
jgonz120 a240062
Caching the parsed NugetVersion and VersionRange objects.
jgonz120 0883567
Fixes from PR
jgonz120 c4adaf7
Avoid creating empty lists
jgonz120 bda30bb
Revert "Caching the parsed NugetVersion and VersionRange objects."
jgonz120 fb7ebd5
Fix netwonsoft json parsing
jgonz120 32aba9a
Add missing reference
jgonz120 8853734
added some examples of the json to be parsed
jgonz120 1b29455
Fix references in comments
jgonz120 1877448
Fixes from PR
jgonz120 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
| #nullable enable | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace NuGet.ProjectModel | ||
| { | ||
| /// <summary> | ||
| /// Splits a string by a delimiter, producing substrings lazily during enumeration. | ||
| /// Skips empty items, behaving equivalently to <see cref="string.Split(char[])"/> with | ||
| /// <see cref="StringSplitOptions.RemoveEmptyEntries"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Unlike <see cref="string.Split(char[])"/> and overloads, <see cref="LazyStringSplit"/> | ||
| /// does not allocate an array for the return, and allocates strings on demand during | ||
| /// enumeration. A custom enumerator type is used so that the only allocations made are | ||
| /// the substrings themselves. We also avoid the large internal arrays assigned by the | ||
| /// methods on <see cref="string"/>. | ||
| /// </remarks> | ||
| internal readonly struct LazyStringSplit : IEnumerable<string> | ||
jgonz120 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private readonly string _input; | ||
| private readonly char _delimiter; | ||
|
|
||
| public LazyStringSplit(string input, char delimiter) | ||
| { | ||
| if (input is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(input)); | ||
| } | ||
|
|
||
| _input = input; | ||
| _delimiter = delimiter; | ||
| } | ||
|
|
||
| public Enumerator GetEnumerator() => new(this); | ||
|
|
||
| IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
|
||
| IEnumerator<string> IEnumerable<string>.GetEnumerator() => GetEnumerator(); | ||
|
|
||
| public IEnumerable<T> Select<T>(Func<string, T> func) | ||
| { | ||
| foreach (string value in this) | ||
| { | ||
| yield return func(value); | ||
| } | ||
| } | ||
|
|
||
| public string First() | ||
| { | ||
| return FirstOrDefault() ?? throw new InvalidOperationException("Sequence is empty."); | ||
| } | ||
|
|
||
| public string? FirstOrDefault() | ||
| { | ||
| var enumerator = new Enumerator(this); | ||
| return enumerator.MoveNext() ? enumerator.Current : null; | ||
| } | ||
|
|
||
| public struct Enumerator : IEnumerator<string> | ||
| { | ||
| private readonly string _input; | ||
| private readonly char _delimiter; | ||
| private int _index; | ||
|
|
||
| internal Enumerator(in LazyStringSplit split) | ||
| { | ||
| _index = 0; | ||
| _input = split._input; | ||
| _delimiter = split._delimiter; | ||
| Current = null!; | ||
| } | ||
|
|
||
| public string Current { get; private set; } | ||
|
|
||
| public bool MoveNext() | ||
| { | ||
| while (_index != _input.Length) | ||
| { | ||
| int delimiterIndex = _input.IndexOf(_delimiter, _index); | ||
|
|
||
| if (delimiterIndex == -1) | ||
| { | ||
| Current = _input.Substring(_index); | ||
| _index = _input.Length; | ||
| return true; | ||
| } | ||
|
|
||
| int length = delimiterIndex - _index; | ||
|
|
||
| if (length == 0) | ||
| { | ||
| _index++; | ||
| continue; | ||
| } | ||
|
|
||
| Current = _input.Substring(_index, length); | ||
| _index = delimiterIndex + 1; | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| object IEnumerator.Current => Current; | ||
|
|
||
| void IEnumerator.Reset() | ||
| { | ||
| _index = 0; | ||
| Current = null!; | ||
| } | ||
|
|
||
| void IDisposable.Dispose() { } | ||
| } | ||
| } | ||
|
|
||
| internal static class LazyStringSplitExtensions | ||
| { | ||
| /// <remarks> | ||
| /// This extension method has special knowledge of the <see cref="LazyStringSplit"/> type and | ||
| /// can compute its result without allocation. | ||
| /// </remarks> | ||
| /// <inheritdoc cref="Enumerable.FirstOrDefault{TSource}(IEnumerable{TSource})"/> | ||
| public static string? FirstOrDefault(this LazyStringSplit lazyStringSplit) | ||
| { | ||
| LazyStringSplit.Enumerator enumerator = lazyStringSplit.GetEnumerator(); | ||
|
|
||
| return enumerator.MoveNext() | ||
| ? enumerator.Current | ||
| : null; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.