[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/security/_ Merged from trunk 25968:

Jim Fulton jim at zope.com
Fri Jul 2 16:36:16 EDT 2004


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

Thanks to Tim for pointing out my omission.



-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/security/_proxy.c
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/security/_proxy.c	2004-07-02 20:33:15 UTC (rev 26064)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/_proxy.c	2004-07-02 20:36:16 UTC (rev 26065)
@@ -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/branches/ZopeX3-3.0/src/zope/security/_zope_security_checker.c
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/security/_zope_security_checker.c	2004-07-02 20:33:15 UTC (rev 26064)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/_zope_security_checker.c	2004-07-02 20:36:16 UTC (rev 26065)
@@ -94,6 +94,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)
 {
@@ -155,6 +159,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)
 {
@@ -351,6 +358,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