mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
Make string extracting for SQLite database a little bit faster and allocate a little bit less memory
This commit is contained in:
parent
c8b174efde
commit
cc9a71bc1b
@ -364,18 +364,17 @@ namespace MCGalaxy.SQL
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string FromUTF8(IntPtr ptr, int len) {
|
public unsafe static string FromUTF8(IntPtr ptr, int len) {
|
||||||
if (ptr == IntPtr.Zero) return "";
|
if (ptr == IntPtr.Zero) return "";
|
||||||
|
byte* mem = (byte*)ptr;
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
len = 0;
|
len = 0;
|
||||||
while (Marshal.ReadByte(ptr, len) != 0) { len++; }
|
while (mem[len] != 0) { len++; }
|
||||||
}
|
}
|
||||||
if (len == 0) return "";
|
if (len == 0) return "";
|
||||||
|
|
||||||
byte[] data = new byte[len];
|
return utf8.GetString(mem, len);
|
||||||
Marshal.Copy(ptr, data, 0, len);
|
|
||||||
return utf8.GetString(data, 0, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DateTime ToDateTime(string text) {
|
public static DateTime ToDateTime(string text) {
|
||||||
@ -659,7 +658,8 @@ namespace MCGalaxy.SQL
|
|||||||
if (count <= 0) return;
|
if (count <= 0) return;
|
||||||
|
|
||||||
paramNames = new string[count];
|
paramNames = new string[count];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
IntPtr p = Interop.sqlite3_bind_parameter_name(handle, i + 1);
|
IntPtr p = Interop.sqlite3_bind_parameter_name(handle, i + 1);
|
||||||
paramNames[i] = SQLiteConvert.FromUTF8(p, -1);
|
paramNames[i] = SQLiteConvert.FromUTF8(p, -1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user