diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2015-09-27 18:55:39 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2015-09-27 23:39:35 +0200 |
commit | 9fe7adc2907afdd2039a67d27328ba82a884561e (patch) | |
tree | 8400d3e7fc84947c48971516abdc0d027bce84b8 /libtrivfs | |
parent | fcf89e5bb006f71ecf5c46b7248216c3dee7e4b8 (diff) |
libtrivfs: optimize the object lookup code
* libtrivfs/mig-decls.h: Remove the specialized cases, they really
blow up these functions that are supposed to be inlined. Also, look
into the dynamically allocated vectors first, because this is the
preferred way of using libtrivfs since 1997.
Diffstat (limited to 'libtrivfs')
-rw-r--r-- | libtrivfs/mig-decls.h | 136 |
1 files changed, 52 insertions, 84 deletions
diff --git a/libtrivfs/mig-decls.h b/libtrivfs/mig-decls.h index 13a9eb71..19091996 100644 --- a/libtrivfs/mig-decls.h +++ b/libtrivfs/mig-decls.h @@ -37,57 +37,41 @@ extern size_t trivfs_num_dynamic_port_buckets; static inline struct trivfs_protid * __attribute__ ((unused)) trivfs_begin_using_protid (mach_port_t port) { - if (trivfs_protid_nportclasses + trivfs_num_dynamic_protid_port_classes > 1) + struct port_info *pi = ports_lookup_port (0, port, 0); + + if (pi) { - struct port_info *pi = ports_lookup_port (0, port, 0); - int i; - - if (pi) - { - for (i = 0; i < trivfs_protid_nportclasses; i++) - if (pi->class == trivfs_protid_portclasses[i]) - return (struct trivfs_protid *) pi; - for (i = 0; i < trivfs_num_dynamic_protid_port_classes; i++) - if (pi->class == trivfs_dynamic_protid_port_classes[i]) - return (struct trivfs_protid *) pi; - ports_port_deref (pi); - } - - return 0; + size_t i; + for (i = 0; i < trivfs_num_dynamic_protid_port_classes; i++) + if (pi->class == trivfs_dynamic_protid_port_classes[i]) + return (struct trivfs_protid *) pi; + for (i = 0; i < trivfs_protid_nportclasses; i++) + if (pi->class == trivfs_protid_portclasses[i]) + return (struct trivfs_protid *) pi; + ports_port_deref (pi); } - else if (trivfs_protid_nportclasses == 1) - return ports_lookup_port (0, port, trivfs_protid_portclasses[0]); - else - return ports_lookup_port (0, port, trivfs_dynamic_protid_port_classes[0]); + + return NULL; } static inline struct trivfs_protid * __attribute__ ((unused)) trivfs_begin_using_protid_payload (unsigned long payload) { - if (trivfs_protid_nportclasses + trivfs_num_dynamic_protid_port_classes > 1) + struct port_info *pi = ports_lookup_payload (NULL, payload, NULL); + + if (pi) { - struct port_info *pi = ports_lookup_payload (NULL, payload, NULL); - int i; - - if (pi) - { - for (i = 0; i < trivfs_protid_nportclasses; i++) - if (pi->class == trivfs_protid_portclasses[i]) - return (struct trivfs_protid *) pi; - for (i = 0; i < trivfs_num_dynamic_protid_port_classes; i++) - if (pi->class == trivfs_dynamic_protid_port_classes[i]) - return (struct trivfs_protid *) pi; - ports_port_deref (pi); - } - - return NULL; + size_t i; + for (i = 0; i < trivfs_num_dynamic_protid_port_classes; i++) + if (pi->class == trivfs_dynamic_protid_port_classes[i]) + return (struct trivfs_protid *) pi; + for (i = 0; i < trivfs_protid_nportclasses; i++) + if (pi->class == trivfs_protid_portclasses[i]) + return (struct trivfs_protid *) pi; + ports_port_deref (pi); } - else if (trivfs_protid_nportclasses == 1) - return ports_lookup_payload (NULL, payload, - trivfs_protid_portclasses[0]); - else - return ports_lookup_payload (NULL, payload, - trivfs_dynamic_protid_port_classes[0]); + + return NULL; } static inline void __attribute__ ((unused)) @@ -100,57 +84,41 @@ trivfs_end_using_protid (struct trivfs_protid *cred) static inline struct trivfs_control * __attribute__ ((unused)) trivfs_begin_using_control (mach_port_t port) { - if (trivfs_cntl_nportclasses + trivfs_num_dynamic_control_port_classes > 1) + struct port_info *pi = ports_lookup_port (0, port, 0); + + if (pi) { - struct port_info *pi = ports_lookup_port (0, port, 0); - int i; - - if (pi) - { - for (i = 0; i < trivfs_cntl_nportclasses; i++) - if (pi->class == trivfs_cntl_portclasses[i]) - return (struct trivfs_control *) pi; - for (i = 0; i < trivfs_num_dynamic_control_port_classes; i++) - if (pi->class == trivfs_dynamic_control_port_classes[i]) - return (struct trivfs_control *) pi; - ports_port_deref (pi); - } - - return 0; + size_t i; + for (i = 0; i < trivfs_num_dynamic_control_port_classes; i++) + if (pi->class == trivfs_dynamic_control_port_classes[i]) + return (struct trivfs_control *) pi; + for (i = 0; i < trivfs_cntl_nportclasses; i++) + if (pi->class == trivfs_cntl_portclasses[i]) + return (struct trivfs_control *) pi; + ports_port_deref (pi); } - else if (trivfs_cntl_nportclasses == 1) - return ports_lookup_port (0, port, trivfs_cntl_portclasses[0]); - else - return ports_lookup_port (0, port, trivfs_dynamic_control_port_classes[0]); + + return NULL; } static inline struct trivfs_control * __attribute__ ((unused)) trivfs_begin_using_control_payload (unsigned long payload) { - if (trivfs_cntl_nportclasses + trivfs_num_dynamic_control_port_classes > 1) + struct port_info *pi = ports_lookup_payload (NULL, payload, NULL); + + if (pi) { - struct port_info *pi = ports_lookup_payload (NULL, payload, NULL); - int i; - - if (pi) - { - for (i = 0; i < trivfs_cntl_nportclasses; i++) - if (pi->class == trivfs_cntl_portclasses[i]) - return (struct trivfs_control *) pi; - for (i = 0; i < trivfs_num_dynamic_control_port_classes; i++) - if (pi->class == trivfs_dynamic_control_port_classes[i]) - return (struct trivfs_control *) pi; - ports_port_deref (pi); - } - - return NULL; + size_t i; + for (i = 0; i < trivfs_num_dynamic_control_port_classes; i++) + if (pi->class == trivfs_dynamic_control_port_classes[i]) + return (struct trivfs_control *) pi; + for (i = 0; i < trivfs_cntl_nportclasses; i++) + if (pi->class == trivfs_cntl_portclasses[i]) + return (struct trivfs_control *) pi; + ports_port_deref (pi); } - else if (trivfs_cntl_nportclasses == 1) - return ports_lookup_payload (NULL, payload, - trivfs_cntl_portclasses[0]); - else - return ports_lookup_payload (NULL, payload, - trivfs_dynamic_control_port_classes[0]); + + return NULL; } static inline void __attribute__ ((unused)) |