summaryrefslogtreecommitdiff
path: root/debian/patches/random-fixes0009-libtrivfs-optimize-the-object-lookup-code.patch
blob: a2985511c6abf889407ee50ce4f875d110e86de9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
From 03093ef7b417e59e5decc96212f5aef322ec6036 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Sun, 27 Sep 2015 18:55:39 +0200
Subject: [PATCH hurd 9/9] 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.
---
 libtrivfs/mig-decls.h | 136 +++++++++++++++++++-------------------------------
 1 file changed, 52 insertions(+), 84 deletions(-)

diff --git a/libtrivfs/mig-decls.h b/libtrivfs/mig-decls.h
index 13a9eb7..1909199 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))
-- 
2.1.4