Overview
Artifact ID: | 5700b8bdea49851c69f7ce8b5dc716b484f756c8 |
---|---|
Ticket: | d3b877c7e0f31d0fcaa20efd8dbaa33b28f42dff
Optimize SQLiteConvert.UTF8ToString for .NET Standard 2.1 |
User & Date: | anonymous 2020-07-04 12:46:52 |
Changes
- foundin changed to: "1.0.113.0"
- icomment:
.NET Standard 2.1 introduced the method `Marshal.PtrToStringUTF8`, which can be used in `SQLiteConvert.UTF8ToString` (similar to using `Marshal.PtrToStringUni` in `SQLite3_UTF16.UTF16ToString`), in order to save allocation of a byte array and to avoid `Marshal.ReadByte()` when using the standard SQLite library. For example: ```c# public static string UTF8ToString(IntPtr nativestring, int nativestringlen) { if (nativestring == IntPtr.Zero || nativestringlen == 0) return String.Empty; #if NETSTANDARD && !NETSTANDARD2_0 if (nativestringlen < 0) return Marshal.PtrToStringUTF8(nativestring); else return Marshal.PtrToStringUTF8(nativestring, nativestringlen); #else if (nativestringlen < 0) { nativestringlen = 0; while (Marshal.ReadByte(nativestring, nativestringlen) != 0) nativestringlen++; if (nativestringlen == 0) return String.Empty; } byte[] byteArray = new byte[nativestringlen]; Marshal.Copy(nativestring, byteArray, 0, nativestringlen); return _utf8.GetString(byteArray, 0, nativestringlen); #endif } ``` Thank you!
- login: "anonymous"
- mimetype: "text/x-markdown"
- private_contact changed to: "4bc1e8ce7495dc3abb20ef2109ec243192989cb7"
- severity changed to: "Minor"
- status changed to: "Open"
- title changed to:
Optimize SQLiteConvert.UTF8ToString for .NET Standard 2.1
- type changed to: "Performance"