I'm working with serializing an XML tree. To make it as fast as possible I am using a raw array of Py_UNICODE characters instead of "".join(l) or something of the sort. One problem I am running into is that I need to append certain strings many times (e.g. '<', '</', '>'). That incurs significant overhead in calls to the Python API. Here is a basic idea of what is happening right now (the real code is more complex):
cdef void append(UnicodeBuffer *ubuffer, unicode un): ----Py_UNICODE *string = PyUnicode_AsUnicode(un) ----... append string to buffer ... cdef void render(UnicodeBuffer *ubuffer, Tag tag): ----append(buffer, u"<") ----append(buffer, tag.name) ----...render attributes with more append calls... ----append(buffer, u">") I'm trying to find something where I could also append with a function like this one: cdef void appendArray(UnicodeBuffer *ubuffer, Py_UNICODE *string, int length): ----...append string to buffer... One possibility is having several arrays of commonly used unicode strings sitting around. In that case render() from above might look like this: cdef void render(UnicodeBuffer *ubuffer, Tag tag): ----appendArray(buffer, ustring_lt, 1) ----append(buffer, tag.name) ----...render attributes with more append calls... ----append(buffer, ustring_gt, 1) What would be the best way to go about this? -Aaron DeVore _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
