@@ -18,9 +18,8 @@ namespace MCServerSharp
18
18
[ SkipLocalsInit ]
19
19
public partial class Utf8String : IComparable < Utf8String > , IEquatable < Utf8String > , ILongHashable
20
20
{
21
- public static Utf8String Empty { get ; } = new Utf8String ( Array . Empty < byte > ( ) ) ;
21
+ public static Utf8String Empty { get ; } = new Utf8String ( ReadOnlyMemory < byte > . Empty ) ;
22
22
23
- private byte [ ] ? _byteArray ;
24
23
private ReadOnlyMemory < byte > _bytes ;
25
24
26
25
public ReadOnlySpan < byte > Bytes => _bytes . Span ;
@@ -30,39 +29,26 @@ public partial class Utf8String : IComparable<Utf8String>, IEquatable<Utf8String
30
29
31
30
#region Constructors
32
31
33
- private Utf8String ( byte [ ] bytes )
34
- {
35
- _byteArray = bytes ;
36
- _bytes = _byteArray . AsMemory ( ) ;
37
- }
38
-
39
32
private Utf8String ( ReadOnlyMemory < byte > bytes )
40
33
{
41
34
_bytes = bytes ;
42
35
}
43
36
44
- private Utf8String ( int length ) : this ( length == 0 ? Array . Empty < byte > ( ) : new byte [ length ] )
45
- {
46
- }
47
-
48
- public Utf8String ( string value ) : this ( StringHelper . Utf8 . GetByteCount ( value ) )
37
+ public Utf8String ( string value ) : this ( StringHelper . Utf8 . GetBytes ( value ) . AsMemory ( ) )
49
38
{
50
- StringHelper . Utf8 . GetBytes ( value , _byteArray ) ;
51
39
}
52
40
53
- public Utf8String ( ReadOnlySpan < char > chars ) : this ( StringHelper . Utf8 . GetByteCount ( chars ) )
41
+ public Utf8String ( ReadOnlySpan < char > utf16 ) : this ( StringHelper . Utf8 . GetBytes ( utf16 ) . AsMemory ( ) )
54
42
{
55
- StringHelper . Utf8 . GetBytes ( chars , _byteArray ) ;
56
43
}
57
44
58
- public Utf8String ( ReadOnlySpan < byte > bytes ) : this ( bytes . Length )
45
+ public Utf8String ( ReadOnlySpan < byte > utf8 ) : this ( utf8 . ToArray ( ) . AsMemory ( ) )
59
46
{
60
- bytes . CopyTo ( _byteArray ) ;
61
47
}
62
48
63
49
#endregion
64
50
65
- public static Utf8String UnsafeWrap ( ReadOnlyMemory < byte > data )
51
+ public static Utf8String WrapUnsafe ( ReadOnlyMemory < byte > data )
66
52
{
67
53
return new Utf8String ( data ) ;
68
54
}
@@ -74,28 +60,13 @@ public static Utf8String Create(ReadOnlySpan<byte> utf8)
74
60
return new Utf8String ( utf8 ) ;
75
61
}
76
62
77
- public static Utf8String Create ( ReadOnlyMemory < byte > utf8 )
78
- {
79
- return Create ( utf8 . Span ) ;
80
- }
81
-
82
- public static Utf8String Create ( Utf8Memory utf8 )
83
- {
84
- return Create ( utf8 . Span ) ;
85
- }
86
-
87
63
public static Utf8String Create ( ReadOnlySpan < char > utf16 )
88
64
{
89
65
if ( utf16 . IsEmpty )
90
66
return Empty ;
91
67
return new Utf8String ( utf16 ) ;
92
68
}
93
69
94
- public static Utf8String Create ( ReadOnlyMemory < char > utf16 )
95
- {
96
- return Create ( utf16 . Span ) ;
97
- }
98
-
99
70
public static Utf8String Create < TState > (
100
71
int length , TState state , SpanAction < byte , TState > action )
101
72
{
@@ -105,8 +76,9 @@ public static Utf8String Create<TState>(
105
76
if ( length == 0 )
106
77
return Empty ;
107
78
108
- var str = new Utf8String ( length ) ;
109
- action . Invoke ( str . _byteArray , state ) ;
79
+ byte [ ] buffer = new byte [ length ] ;
80
+ var str = new Utf8String ( buffer . AsMemory ( ) ) ;
81
+ action . Invoke ( buffer , state ) ;
110
82
return str ;
111
83
}
112
84
@@ -244,9 +216,9 @@ public static Utf8String Concat(ReadOnlySpan<byte> value1, ReadOnlySpan<byte> va
244
216
dst = dst [ value2 . Length ..] ;
245
217
246
218
value3 . CopyTo ( dst ) ;
247
- dst = dst [ value3 . Length ..] ;
219
+ // dst = dst[value3.Length..];
248
220
249
- return new Utf8String ( bytes ) ;
221
+ return new Utf8String ( bytes . AsMemory ( ) ) ;
250
222
}
251
223
252
224
public static Utf8String Concat ( Utf8String ? value1 , Utf8String ? value2 , Utf8String ? value3 )
0 commit comments