(10000, 100 * _UCS);
+
///
/// Initialize the runtime...
///
@@ -1524,7 +1530,7 @@ internal static IntPtr PyUnicode_FromString(string s)
///
/// PyStringType or PyUnicodeType object to convert
/// Managed String
- internal static string GetManagedString(IntPtr op)
+ internal static unsafe string GetManagedString(IntPtr op)
{
IntPtr type = PyObject_TYPE(op);
@@ -1541,9 +1547,20 @@ internal static string GetManagedString(IntPtr op)
int length = (int)PyUnicode_GetSize(op);
int size = length * _UCS;
- var buffer = new byte[size];
- Marshal.Copy(p, buffer, 0, size);
- return PyEncoding.GetString(buffer, 0, size);
+ if (size <= UcsStringsInternDictionary.MaxItemSize)
+ {
+ var ucsStringMemBlock = new RawImmutableMemBlock(p, size);
+ string str;
+ if (!UcsStringsInternDictionary.TryGetValue(ucsStringMemBlock, out str))
+ {
+ str = PyEncoding.GetString((byte*)p, size);
+ UcsStringsInternDictionary.AddUnsafe(ucsStringMemBlock, str);
+ }
+
+ return str;
+ }
+
+ return PyEncoding.GetString((byte*)p, size);
}
return null;
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy