Commit adeb731
authored
refactor: move dynamic import resolution to unit initialization (#63)
## Summary
Move dynamic library symbol resolution (`dlopen`/`dlsym`) from lazy
per-call resolution to one-time unit initialization for ARM hardware
capability detection on Linux, Android, BSD, and macOS (Darwin).
## Changes
### HlpArmHwCapProvider.pas (Linux/Android and BSD)
- Renamed `ResolveOnce` to `ResolveDynamicImports` and removed the
manual `FResolved` boolean guard, since the initialization section
guarantees single execution.
- Removed `ResolveOnce` calls from `GetHwCap` and `GetHwCap2` — the
function pointers are already resolved by the time any caller can
reach them.
- Added an `initialization` section that calls
`ResolveDynamicImports` at unit load time.
- Relaxed visibility from `strict private` to `private` so the
initialization section can access the method.
### HlpDarwinSysCtl.pas (macOS/iOS)
- Same refactor: renamed `ResolveOnce` to `ResolveDynamicImports`,
removed the `FResolved` guard, removed the call from `HasFeature`,
and moved resolution to an `initialization` section.
## Rationale
The previous pattern resolved imports lazily on first use with a
boolean guard. This worked but added a branch to every call of
`GetHwCap`, `GetHwCap2`, and `HasFeature`. Since these function
pointers never change after resolution, performing the `dlopen`/`dlsym`
once at unit initialization is simpler, removes the redundant flag
field, and eliminates repeated nil-check overhead on the hot path.1 parent 1b2405e commit adeb731
2 files changed
Lines changed: 17 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
96 | 95 | | |
97 | | - | |
98 | | - | |
| 96 | + | |
| 97 | + | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
| |||
110 | 109 | | |
111 | 110 | | |
112 | 111 | | |
113 | | - | |
114 | 112 | | |
115 | | - | |
116 | | - | |
| 113 | + | |
| 114 | + | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
| |||
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
142 | | - | |
| 140 | + | |
143 | 141 | | |
144 | 142 | | |
145 | 143 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | 144 | | |
150 | | - | |
151 | 145 | | |
152 | 146 | | |
153 | 147 | | |
| |||
163 | 157 | | |
164 | 158 | | |
165 | 159 | | |
166 | | - | |
167 | 160 | | |
168 | 161 | | |
169 | 162 | | |
| |||
172 | 165 | | |
173 | 166 | | |
174 | 167 | | |
175 | | - | |
176 | 168 | | |
177 | 169 | | |
178 | 170 | | |
| |||
185 | 177 | | |
186 | 178 | | |
187 | 179 | | |
188 | | - | |
| 180 | + | |
189 | 181 | | |
190 | 182 | | |
191 | 183 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | 184 | | |
196 | | - | |
197 | 185 | | |
198 | 186 | | |
199 | 187 | | |
| |||
216 | 204 | | |
217 | 205 | | |
218 | 206 | | |
219 | | - | |
220 | 207 | | |
221 | 208 | | |
222 | 209 | | |
| |||
233 | 220 | | |
234 | 221 | | |
235 | 222 | | |
236 | | - | |
237 | 223 | | |
238 | 224 | | |
239 | 225 | | |
| |||
259 | 245 | | |
260 | 246 | | |
261 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
262 | 253 | | |
263 | 254 | | |
264 | 255 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | 34 | | |
36 | | - | |
37 | | - | |
| 35 | + | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | | - | |
| 65 | + | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | 69 | | |
74 | | - | |
75 | 70 | | |
76 | 71 | | |
77 | 72 | | |
| |||
107 | 102 | | |
108 | 103 | | |
109 | 104 | | |
110 | | - | |
111 | | - | |
112 | 105 | | |
113 | 106 | | |
114 | 107 | | |
| |||
123 | 116 | | |
124 | 117 | | |
125 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
126 | 122 | | |
127 | 123 | | |
128 | 124 | | |
| |||
0 commit comments