[Zope3-checkins] SVN: Zope3/trunk/src/zope/security/_ Added comments explaining the slot-performance hacks I added.

Jim Fulton jim at zope.com
Thu Jun 24 11:12:02 EDT 2004


Log message for revision 25968:
Added comments explaining the slot-performance hacks I added.

Thanks to Tim for pointing out my omission.



-=-
Modified: Zope3/trunk/src/zope/security/_proxy.c
===================================================================
--- Zope3/trunk/src/zope/security/_proxy.c	2004-06-24 13:58:59 UTC (rev 25967)
+++ Zope3/trunk/src/zope/security/_proxy.c	2004-06-24 15:12:01 UTC (rev 25968)
@@ -117,6 +117,12 @@
 {
   PyObject *r;
 
+  /* If the checker has __setitem__, we call it's slot rather than
+     calling check or check_getattr. Why? Because calling operator slots
+     is much faster than calling methods and security checks are done so
+     often that speed matters.  So we have this hack of using
+     almost-arbitrary operations to represent methods that we call
+     alot.  */
   if (self->proxy_checker->ob_type->tp_as_mapping != NULL
       && self->proxy_checker->ob_type->tp_as_mapping->mp_ass_subscript != NULL
       && meth != str_check_setattr)
@@ -133,6 +139,12 @@
   return 0;
 }
 
+/* If the checker has __getitem__, we call it's slot rather than
+   calling proxy. Why? Because calling operator slots
+   is much faster than calling methods and security checks are done so
+   often that speed matters.  So we have this hack of using
+   almost-arbitrary operations to represent methods that we call
+   alot.  */
 #define PROXY_RESULT(self, result) \
 if (result != NULL) { \
   PyObject *tmp; \

Modified: Zope3/trunk/src/zope/security/_zope_security_checker.c
===================================================================
--- Zope3/trunk/src/zope/security/_zope_security_checker.c	2004-06-24 13:58:59 UTC (rev 25967)
+++ Zope3/trunk/src/zope/security/_zope_security_checker.c	2004-06-24 15:12:01 UTC (rev 25968)
@@ -107,6 +107,10 @@
 
 
 /*     def check(self, object, name): */
+
+/* Note that we have an int version gere because we will use it for
+   __setitem__, as describd below */
+
 static int
 Checker_check_int(Checker *self, PyObject *object, PyObject *name)
 {
@@ -168,6 +172,9 @@
   }
 }
 
+/* Here we have the non-int version, implemented using the int
+   version, which is exposed as a method */
+
 static PyObject *
 Checker_check(Checker *self, PyObject *args)
 {
@@ -364,6 +371,13 @@
     {NULL}  /* Sentinel */
 };
 
+/* We create operator aliases for check and proxy. Why? Because
+   calling operator slots is much faster than calling methods and
+   security checks are done so often that speed matters.  So we have
+   this hack of using almost-arbitrary operations to represent methods
+   that we call alot.  The security proxy implementation participates
+   in the same hack. */
+
 static PyMappingMethods Checker_as_mapping = {
 	/* mp_length        */ (inquiry)NULL,
 	/* mp_subscript     */ (binaryfunc)Checker_proxy,



More information about the Zope3-Checkins mailing list