mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-23 15:06:32 +00:00
Add new string type rdcinflexiblestr specifically for structured data
* This is a string type which heavily optimises for immutability and minimal storage. It only contains one pointer to the string data and always reallocates on modify. For compile-time literals it doesn't modify or allocate. * On x64 we use the top bit in a tagged pointer to store a flag of whether it's heap or literal, on other platforms it uses a separate field (meaning another pointer sized value effectively, including padding). * This is best for structured data which tends to use a lot of immutable strings for type/name information, and only a few for actual string data (which are only allocated once and aren't modified after that). Similarly we rarely want to know only the size of any of these strings, we want the whole string so not explicitly storing the size is not a big deal. * Overall this reduces SDObject from 128 bytes to 80 bytes.
This commit is contained in:
@@ -47,7 +47,7 @@ inline SDChunk *MakeFromArgsTuple<SDChunk>(PyObject *args)
|
||||
if(!SWIG_IsOK(res))
|
||||
SWIG_exception_fail(SWIG_ArgError(res), "invalid name used to create SDChunk, expected string");
|
||||
|
||||
result = new SDChunk(name.c_str());
|
||||
result = new SDChunk(name);
|
||||
|
||||
return result;
|
||||
fail:
|
||||
@@ -77,7 +77,7 @@ inline SDObject *MakeFromArgsTuple<SDObject>(PyObject *args)
|
||||
SWIG_exception_fail(SWIG_ArgError(res),
|
||||
"invalid type name used to create SDObject, expected string");
|
||||
|
||||
result = new SDObject(name.c_str(), typeName);
|
||||
result = new SDObject(name, typeName);
|
||||
|
||||
return result;
|
||||
fail:
|
||||
|
||||
@@ -664,6 +664,67 @@ struct TypeConversion<rdcstr, false>
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TypeConversion<rdcinflexiblestr, false>
|
||||
{
|
||||
static swig_type_info *GetTypeInfo()
|
||||
{
|
||||
static swig_type_info *cached_type_info = NULL;
|
||||
|
||||
if(cached_type_info)
|
||||
return cached_type_info;
|
||||
|
||||
cached_type_info = SWIG_TypeQuery("rdcinflexiblestr *");
|
||||
|
||||
return cached_type_info;
|
||||
}
|
||||
|
||||
static int ConvertFromPy(PyObject *in, rdcinflexiblestr &out)
|
||||
{
|
||||
if(PyUnicode_Check(in))
|
||||
{
|
||||
PyObject *bytes = PyUnicode_AsUTF8String(in);
|
||||
|
||||
if(!bytes)
|
||||
return SWIG_ERROR;
|
||||
|
||||
char *buf = NULL;
|
||||
Py_ssize_t size = 0;
|
||||
|
||||
int ret = PyBytes_AsStringAndSize(bytes, &buf, &size);
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
out = rdcstr(buf, size);
|
||||
|
||||
Py_DecRef(bytes);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
Py_DecRef(bytes);
|
||||
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
swig_type_info *type_info = GetTypeInfo();
|
||||
if(!type_info)
|
||||
return SWIG_ERROR;
|
||||
|
||||
rdcinflexiblestr *ptr = NULL;
|
||||
int res = SWIG_ConvertPtr(in, (void **)&ptr, type_info, 0);
|
||||
if(SWIG_IsOK(res))
|
||||
out = *ptr;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyObject *ConvertToPy(const rdcinflexiblestr &in)
|
||||
{
|
||||
return PyUnicode_FromString(in.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
#include "structured_conversion.h"
|
||||
|
||||
// free functions forward to struct
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
// completely ignore types that we custom convert to/from a native python type
|
||||
%ignore rdcdatetime;
|
||||
%ignore rdcstr;
|
||||
%ignore rdcinflexiblestr;
|
||||
%ignore rdcliteral;
|
||||
%ignore rdcpair;
|
||||
%ignore bytebuf;
|
||||
@@ -193,6 +194,7 @@
|
||||
}
|
||||
|
||||
SIMPLE_TYPEMAPS(rdcstr)
|
||||
SIMPLE_TYPEMAPS(rdcinflexiblestr)
|
||||
SIMPLE_TYPEMAPS(rdcdatetime)
|
||||
SIMPLE_TYPEMAPS(bytebuf)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user