Skip to content

Commit 3a392b0

Browse files
committed
Do not use direct Slice constructor
1 parent af009ac commit 3a392b0

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

FoundationDB.Client/FdbKey.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static Slice Increment(Slice slice)
8383
throw Fdb.Errors.CannotIncrementKey();
8484
}
8585

86-
return new Slice(tmp, 0, lastNonFFByte + 1);
86+
return tmp.AsSlice(0, lastNonFFByte + 1);
8787
}
8888

8989
/// <summary>Merge an array of keys with a same prefix, all sharing the same buffer</summary>
@@ -162,7 +162,7 @@ internal static Slice[] SplitIntoSegments([NotNull] byte[] buffer, int start, [N
162162
int p = start;
163163
foreach (var end in endOffsets)
164164
{
165-
result[i++] = new Slice(buffer, p, end - p);
165+
result[i++] = buffer.AsSlice(p, end - p);
166166
p = end;
167167
}
168168

FoundationDB.Client/Filters/Logging/FdbLoggedTransaction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private Slice Grab(Slice slice)
114114
int start = m_offset;
115115
slice.CopyTo(m_buffer, m_offset);
116116
m_offset += slice.Count;
117-
return new Slice(m_buffer, start, slice.Count);
117+
return m_buffer.AsSlice(start, slice.Count);
118118
}
119119
}
120120

FoundationDB.Client/Native/FdbNative.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public static Slice ToNativeString(string value, bool nullTerminated)
309309
{
310310
result = Slice.DefaultEncoding.GetBytes(value);
311311
}
312-
return new Slice(result, 0, result.Length);
312+
return Slice.CreateUnsafe(result, 0, result.Length);
313313
}
314314

315315

@@ -696,7 +696,7 @@ public static FdbError FutureGetValue(FutureHandle future, out bool valuePresent
696696
{
697697
var bytes = new byte[valueLength];
698698
Marshal.Copy(new IntPtr(ptr), bytes, 0, valueLength);
699-
value = new Slice(bytes, 0, valueLength);
699+
value = Slice.CreateUnsafe(bytes, 0, valueLength);
700700
}
701701
else
702702
{
@@ -785,8 +785,8 @@ public static FdbError FutureGetKeyValueArray(FutureHandle future, out KeyValueP
785785
Marshal.Copy(kvp[i].Value, page, p + kl, vl);
786786

787787
result[i] = new KeyValuePair<Slice, Slice>(
788-
new Slice(page, p, kl),
789-
new Slice(page, p + kl, vl)
788+
page.AsSlice(p, kl),
789+
page.AsSlice(p + kl, vl)
790790
);
791791

792792
p += kl + vl;

FoundationDB.Client/Tuples/Encoding/TupleParser.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,7 @@ public static Slice ParseBytes(Slice slice)
883883
Contract.Requires(slice.HasValue && slice[0] == TupleTypes.Bytes && slice[-1] == 0);
884884
if (slice.Count <= 2) return Slice.Empty;
885885

886-
var decoded = UnescapeByteString(slice.Array, slice.Offset + 1, slice.Count - 2);
887-
888-
return new Slice(decoded.Array, decoded.Offset, decoded.Count);
886+
return UnescapeByteString(slice.Array, slice.Offset + 1, slice.Count - 2);
889887
}
890888

891889
/// <summary>Parse a tuple segment containing an ASCII string stored as a byte array</summary>

FoundationDB.Layers.Common/Blobs/FdbBlob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ await trans
274274
})
275275
.ConfigureAwait(false);
276276

277-
return new Slice(buffer, 0, buffer.Length);
277+
return buffer.AsSlice(0, buffer.Length);
278278
}
279279

280280
/// <summary>

0 commit comments

Comments
 (0)