From 1e647a570d9c42de915bc1204ff21ea5fa4e6b17 Mon Sep 17 00:00:00 2001 From: mano-wii Date: Thu, 27 Sep 2018 00:22:57 -0300 Subject: Python GPU module: replace `PyArg_ParseTupleAndKeywords` by `_PyArg_ParseTupleAndKeywordsFast` part of T47811 ("for faster argument parsing"). --- source/blender/python/gpu/gpu_py_batch.c | 17 ++++++------ source/blender/python/gpu/gpu_py_offscreen.c | 33 ++++++++++++++---------- source/blender/python/gpu/gpu_py_shader.c | 13 +++++----- source/blender/python/gpu/gpu_py_vertex_buffer.c | 17 ++++++------ source/blender/python/gpu/gpu_py_vertex_format.c | 8 +++--- 5 files changed, 46 insertions(+), 42 deletions(-) (limited to 'source/blender/python') diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c index 2a4868d61d0..4e7804f382f 100644 --- a/source/blender/python/gpu/gpu_py_batch.c +++ b/source/blender/python/gpu/gpu_py_batch.c @@ -96,16 +96,15 @@ success: static PyObject *bpygpu_Batch_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) { - const char * const keywords[] = {"type", "buf", NULL}; - struct { GPUPrimType type_id; BPyGPUVertBuf *py_buf; } params; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, - "$O&O!:GPUBatch.__new__", (char **)keywords, + static const char *_keywords[] = {"type", "buf", NULL}; + static _PyArg_Parser _parser = {"$O&O!:GPUBatch.__new__", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, bpygpu_ParsePrimType, ¶ms.type_id, &BPyGPUVertBuf_Type, ¶ms.py_buf)) { @@ -183,14 +182,14 @@ PyDoc_STRVAR(bpygpu_VertBatch_program_set_builtin_doc, ); static PyObject *bpygpu_VertBatch_program_set_builtin(BPyGPUBatch *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"id", NULL}; - struct { const char *shader; } params; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "s:program_set_builtin", (char **)kwlist, + static const char *_keywords[] = {"id", NULL}; + static _PyArg_Parser _parser = {"s:program_set_builtin", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, ¶ms.shader)) { return NULL; diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c index 866a98bbb9f..d0ba48b69c5 100644 --- a/source/blender/python/gpu/gpu_py_offscreen.c +++ b/source/blender/python/gpu/gpu_py_offscreen.c @@ -62,14 +62,14 @@ static PyObject *bpygpu_offscreen_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"width", "height", "samples", NULL}; - GPUOffScreen *ofs; int width, height, samples = 0; char err_out[256]; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "ii|i:new", (char **)(kwlist), + static const char *_keywords[] = {"width", "height", "samples", NULL}; + static _PyArg_Parser _parser = {"ii|i:GPUOffScreen.__new__", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, &width, &height, &samples)) { return NULL; @@ -134,13 +134,14 @@ PyDoc_STRVAR(bpygpu_offscreen_bind_doc, ); static PyObject *bpygpu_offscreen_bind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"save", NULL}; bool save = true; BPY_GPU_OFFSCREEN_CHECK_OBJ(self); - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|O&:bind", (char **)(kwlist), + static const char *_keywords[] = {"save", NULL}; + static _PyArg_Parser _parser = {"|O&:bind", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, PyC_ParseBool, &save)) { return NULL; @@ -160,13 +161,14 @@ PyDoc_STRVAR(bpygpu_offscreen_unbind_doc, ); static PyObject *bpygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"restore", NULL}; bool restore = true; BPY_GPU_OFFSCREEN_CHECK_OBJ(self); - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "|O&:unbind", (char **)(kwlist), + static const char *_keywords[] = {"restore", NULL}; + static _PyArg_Parser _parser = {"|O&:unbind", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, PyC_ParseBool, &restore)) { return NULL; @@ -194,8 +196,6 @@ PyDoc_STRVAR(bpygpu_offscreen_draw_view3d_doc, ); static PyObject *bpygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"scene", "view_layer", "view3d", "region", "projection_matrix", "modelview_matrix", NULL}; - MatrixObject *py_mat_modelview, *py_mat_projection; PyObject *py_scene, *py_view_layer, *py_region, *py_view3d; @@ -208,8 +208,13 @@ static PyObject *bpygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *a BPY_GPU_OFFSCREEN_CHECK_OBJ(self); - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "OOOOO&O&:draw_view3d", (char **)(kwlist), + static const char *_keywords[] = { + "scene", "view_layer", "view3d", "region", + "projection_matrix", "modelview_matrix", NULL}; + + static _PyArg_Parser _parser = {"OOOOO&O&:draw_view3d", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, &py_scene, &py_view_layer, &py_view3d, &py_region, Matrix_Parse4x4, &py_mat_projection, Matrix_Parse4x4, &py_mat_modelview) || diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index a10fe22a7f2..2fc5f5278f0 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -85,10 +85,6 @@ static int bpygpu_pyLong_as_shader_enum(PyObject *o) static PyObject *bpygpu_shader_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) { - static const char *kwlist[] = { - "vertexcode", "fragcode", "geocode", - "libcode", "defines", NULL}; - struct { const char *vertexcode; const char *fragcode; @@ -97,8 +93,13 @@ static PyObject *bpygpu_shader_new(PyTypeObject *UNUSED(type), PyObject *args, P const char *defines; } params = {0}; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "ss|$sss:GPUShader.__new__", (char **)kwlist, + static const char *_keywords[] = { + "vertexcode", "fragcode", "geocode", + "libcode", "defines", NULL}; + + static _PyArg_Parser _parser = {"ss|$sss:GPUShader.__new__", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, ¶ms.vertexcode, ¶ms.fragcode, ¶ms.geocode, ¶ms.libcode, ¶ms.defines)) { diff --git a/source/blender/python/gpu/gpu_py_vertex_buffer.c b/source/blender/python/gpu/gpu_py_vertex_buffer.c index 1b8a257425b..53fbbf623fa 100644 --- a/source/blender/python/gpu/gpu_py_vertex_buffer.c +++ b/source/blender/python/gpu/gpu_py_vertex_buffer.c @@ -213,16 +213,15 @@ static int bpygpu_find_id(const GPUVertFormat *fmt, const char *id) static PyObject *bpygpu_VertBuf_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) { - const char * const keywords[] = {"len", "format", NULL}; - struct { BPyGPUVertFormat *py_fmt; uint len; } params; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, - "$IO!:GPUVertBuf.__new__", (char **)keywords, + static const char *_keywords[] = {"len", "format", NULL}; + static _PyArg_Parser _parser = {"$IO!:GPUVertBuf.__new__", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, ¶ms.len, &BPyGPUVertFormat_Type, ¶ms.py_fmt)) { @@ -241,15 +240,15 @@ PyDoc_STRVAR(bpygpu_VertBuf_fill_doc, ); static PyObject *bpygpu_VertBuf_fill(BPyGPUVertBuf *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"id", "data", NULL}; - struct { uint id; PyObject *py_seq_data; } params; - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "$IO:fill", (char **)kwlist, + static const char *_keywords[] = {"id", "data", NULL}; + static _PyArg_Parser _parser = {"$IO:fill", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, ¶ms.id, ¶ms.py_seq_data)) { diff --git a/source/blender/python/gpu/gpu_py_vertex_format.c b/source/blender/python/gpu/gpu_py_vertex_format.c index 96ca4003dc9..34f6af75477 100644 --- a/source/blender/python/gpu/gpu_py_vertex_format.c +++ b/source/blender/python/gpu/gpu_py_vertex_format.c @@ -154,8 +154,6 @@ PyDoc_STRVAR(bpygpu_VertFormat_attr_add_doc, ); static PyObject *bpygpu_VertFormat_attr_add(BPyGPUVertFormat *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"id", "comp_type", "len", "fetch_mode", NULL}; - struct { const char *id; GPUVertCompType comp_type; @@ -168,8 +166,10 @@ static PyObject *bpygpu_VertFormat_attr_add(BPyGPUVertFormat *self, PyObject *ar return NULL; } - if (!PyArg_ParseTupleAndKeywords( - args, kwds, "$sO&IO&:attr_add", (char **)kwlist, + static const char *_keywords[] = {"id", "comp_type", "len", "fetch_mode", NULL}; + static _PyArg_Parser _parser = {"$sO&IO&:attr_add", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kwds, &_parser, ¶ms.id, bpygpu_ParseVertCompType, ¶ms.comp_type, ¶ms.len, -- cgit v1.2.3