This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
BufferWriter.WriteLine String/Utf8String #2176
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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
34 changes: 34 additions & 0 deletions
34
src/System.Buffers.ReaderWriter/System/Buffers/Writer/BufferWriterT_ints.cs
This file contains 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,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Buffers.Text; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Buffers.Writer | ||
{ | ||
public ref partial struct BufferWriter<T> where T : IBufferWriter<byte> | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Write(int value, StandardFormat format = default) | ||
{ | ||
int written; | ||
while (!Utf8Formatter.TryFormat(value, Buffer, out written, format)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for myself. Why don't you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean why don't I do "out int written"? If yes, then because of scoping. I need written outside of the while loop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thanks. Didn't know the expression variable scoping is different for loops. |
||
{ | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Write(ulong value, StandardFormat format = default) | ||
{ | ||
int written; | ||
while (!Utf8Formatter.TryFormat(value, Buffer, out written, format)) | ||
{ | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
} | ||
} |
This file contains 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
38 changes: 38 additions & 0 deletions
38
src/System.Buffers.ReaderWriter/System/Buffers/Writer/BufferWriterT_writable.cs
This file contains 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,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Buffers.Text; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace System.Buffers.Writer | ||
{ | ||
public ref partial struct BufferWriter<T> where T : IBufferWriter<byte> | ||
{ | ||
public void Write<TWritable>(TWritable value, TransformationFormat format) where TWritable : IWritable | ||
{ | ||
int written; | ||
while (true) | ||
{ | ||
while (!value.TryWrite(Buffer, out written, format.Format)) | ||
{ | ||
Enlarge(); | ||
} | ||
if (format.TryTransform(Buffer, ref written)) break; | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Write<TWritable>(TWritable value, StandardFormat format) where TWritable : IWritable | ||
{ | ||
int written; | ||
while (!value.TryWrite(Buffer, out written, format)) | ||
{ | ||
Enlarge(); | ||
} | ||
Advance(written); | ||
} | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I copied/pasted it from the non-generic writer. It should be a property. I will change.