فهرست منبع

avoid byte[] allocation when reading empty strings from native memory

Stephan Zehetner 7 سال پیش
والد
کامیت
3729329a3f
1فایلهای تغییر یافته به همراه3 افزوده شده و 0 حذف شده
  1. 3 0
      src/csharp/Grpc.Core/Internal/MarshalUtils.cs

+ 3 - 0
src/csharp/Grpc.Core/Internal/MarshalUtils.cs

@@ -35,6 +35,9 @@ namespace Grpc.Core.Internal
         /// </summary>
         public static string PtrToStringUTF8(IntPtr ptr, int len)
         {
+            if (len == 0)
+                return "";
+
             var bytes = new byte[len];
             Marshal.Copy(ptr, bytes, 0, len);
             return EncodingUTF8.GetString(bytes);