Skip to content

Commit

Permalink
Refactor Wrapper_[get,set]attro
Browse files Browse the repository at this point in the history
* Make use of the fact that no empty wrappers exist any more.
* This hand craftet startswith has no meassurable speed boost => omitted.
* The usual spaces/tabs/indent stuff.
  • Loading branch information
stephan-hof committed Feb 22, 2017
1 parent 4a1bfd5 commit 23a2922
Showing 1 changed file with 35 additions and 48 deletions.
83 changes: 35 additions & 48 deletions src/Acquisition/_Acquisition.c
Expand Up @@ -828,69 +828,56 @@ Wrapper_getattro(Wrapper *self, PyObject *oname)
static PyObject *
Xaq_getattro(Wrapper *self, PyObject *oname)
{
PyObject *tmp=NULL;
PyObject *result;
char *name="";

/* Special case backward-compatible acquire method. */
if ((tmp = convert_name(oname)) == NULL) {
return NULL;
}
name = PyBytes_AS_STRING(tmp);

if (*name=='a' && name[1]=='c' && strcmp(name+2,"quire")==0)
result = Py_FindAttr(OBJECT(self),oname);

else if (self->obj || self->container)
result = Wrapper_findattr(self, oname, NULL, NULL, NULL, 1, 0, 0, 0);
PyObject *tmp, *result;

/* Maybe we are getting initialized? */
else result = Py_FindAttr(OBJECT(self),oname);
if ((tmp = convert_name(oname)) == NULL) {
return NULL;
}

Py_XDECREF(tmp);
/* Special case backward-compatible acquire method. */
if (STR_EQ(PyBytes_AS_STRING(tmp), "acquire")) {
result = Py_FindAttr(OBJECT(self), oname);
} else {
result = Wrapper_findattr(self, oname, NULL, NULL, NULL, 1, 0, 0, 0);
}

return result;
Py_DECREF(tmp);
return result;
}

static int
Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v)
{
PyObject *tmp=NULL;
char *name="";
int result;

if ((tmp = convert_name(oname)) == NULL) {
return -1;
}
name = PyBytes_AS_STRING(tmp);
PyObject *tmp = NULL;
char *name = "";
int result;

if ((*name=='a' && name[1]=='q' && name[2]=='_'
&& strcmp(name+3,"parent")==0) || (strcmp(name, "__parent__")==0))
{
Py_XINCREF(v);
ASSIGN(self->container, v);
result = 0;
if ((tmp = convert_name(oname)) == NULL) {
return -1;
}

else if (self->obj)
{
/* Unwrap passed in wrappers! */
while (v && isWrapper(v))
v=WRAPPER(v)->obj;
name = PyBytes_AS_STRING(tmp);

if (v) result = PyObject_SetAttr(self->obj, oname, v);
else result = PyObject_DelAttr(self->obj, oname);
}
else
{
PyErr_SetString(PyExc_AttributeError,
"Attempt to set attribute on empty acquisition wrapper");
result = -1;
if (STR_EQ(name, "aq_parent") || STR_EQ(name, "__parent__")) {
Py_XINCREF(v);
ASSIGN(self->container, v);
result = 0;
} else {
/* Unwrap passed in wrappers! */
while (v && isWrapper(v)) {
v = WRAPPER(v)->obj;
}
if (v) {
result = PyObject_SetAttr(self->obj, oname, v);
}
else {
result = PyObject_DelAttr(self->obj, oname);
}
}

Py_XDECREF(tmp);

return result;
Py_DECREF(tmp);
return result;
}

static int
Expand Down

0 comments on commit 23a2922

Please sign in to comment.