hadashiA / VYaml

The extra fast, low memory footprint YAML library for C#, focued on .NET and Unity.
MIT License
295 stars 16 forks source link

Replace System.String with ReadOnlySpan<System.Char> in Utf8YamlEmitter.WriteString #99

Closed ArchLeaders closed 1 week ago

ArchLeaders commented 3 months ago

Changes the input parameter of Utf8YamlEmitter.WriteString from System.String to System.ReadOnlySpan<char> for more optimal writing scenarios.

Note, this PR changes the project LangVersion from 9 to 11 to use pattern matching on a ReadOnlySpan<char>.

hadashiA commented 1 month ago

@ArchLeaders Ok thanks.

There is one problem, however.

Currently, We need to write it in C# 9 because it shares source code with the Unity package. Is it possible to get it to compile through the Unity environment?

I would like to check on my end, but it will be a bit later.

ArchLeaders commented 1 month ago

Unfortunately, I have no idea how to use Unity. I can look into it, but it will probably take just as long to figure out how to use Unity as it would to wait.

I'll comment here if I find anything though.

CyberAndrii commented 1 month ago

Hi @hadashiA!

Is there any reason to compile it through Unity instead of using a precompiled dll? If it needs some Unity APIs you could reference Unity's dlls in csproj (but don't ship them with the package). That's how I usually do it in my projects.

Also, changing type of a parameter is a breaking change and I really hate when projects do that. Please add the original method back as an overload.

ArchLeaders commented 1 month ago

Also, changing type of a parameter is a breaking change and I really hate when projects do that. Please add the original method back as an overload.

Makes sense, although string can be implicitly converted to ReadOnlySpan<char> so it won't break anything.

hadashiA commented 1 month ago

Hi,

Is there any reason to compile it through Unity instead of using a precompiled dll? If it needs some Unity APIs you could reference Unity's dlls in csproj (but don't ship them with the package). That's how I usually do it in my projects.

Ah yes,, perhaps we could distribute the dlls. Source code distribution may have the advantage that it is easier for users to debug and understand. However, when I developed this, there was not much difference in compilers between .NET and Unity, but not so much now. I think I'll switch to the Dll distribution.

Also, changing type of a parameter is a breaking change and I really hate when projects do that. Please add the original method back as an overload.

👍

rube200 commented 2 weeks ago

Makes sense, although string can be implicitly converted to ReadOnlySpan<char> so it won't break anything.

I am not sure but i think it still breaks, you will need to recompile the project that refs on that case

hadashiA commented 1 week ago

In #114, I've been added ReadOnlySpan<char> overloads.
The dll distribution is a major change. I would like to discuss it in a separate issue. Thanks.