array_len and buf_len are in integers, not bytes */
| 276 | |
| 277 | /* array_len and buf_len are in integers, not bytes */ |
| 278 | static void |
| 279 | zap_leaf_array_read(zap_leaf_t *l, uint16_t chunk, |
| 280 | int array_int_len, int array_len, int buf_int_len, uint64_t buf_len, |
| 281 | void *buf) |
| 282 | { |
| 283 | int len = MIN(array_len, buf_len); |
| 284 | int byten = 0; |
| 285 | uint64_t value = 0; |
| 286 | char *p = buf; |
| 287 | |
| 288 | ASSERT3U(array_int_len, <=, buf_int_len); |
| 289 | |
| 290 | /* Fast path for one 8-byte integer */ |
| 291 | if (array_int_len == 8 && buf_int_len == 8 && len == 1) { |
| 292 | struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array; |
| 293 | uint8_t *ip = la->la_array; |
| 294 | uint64_t *buf64 = buf; |
| 295 | |
| 296 | *buf64 = (uint64_t)ip[0] << 56 | (uint64_t)ip[1] << 48 | |
| 297 | (uint64_t)ip[2] << 40 | (uint64_t)ip[3] << 32 | |
| 298 | (uint64_t)ip[4] << 24 | (uint64_t)ip[5] << 16 | |
| 299 | (uint64_t)ip[6] << 8 | (uint64_t)ip[7]; |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | /* Fast path for an array of 1-byte integers (eg. the entry name) */ |
| 304 | if (array_int_len == 1 && buf_int_len == 1 && |
| 305 | buf_len > array_len + ZAP_LEAF_ARRAY_BYTES) { |
| 306 | while (chunk != CHAIN_END) { |
| 307 | struct zap_leaf_array *la = |
| 308 | &ZAP_LEAF_CHUNK(l, chunk).l_array; |
| 309 | bcopy(la->la_array, p, ZAP_LEAF_ARRAY_BYTES); |
| 310 | p += ZAP_LEAF_ARRAY_BYTES; |
| 311 | chunk = la->la_next; |
| 312 | } |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | while (len > 0) { |
| 317 | struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, chunk).l_array; |
| 318 | |
| 319 | ASSERT3U(chunk, <, ZAP_LEAF_NUMCHUNKS(l)); |
| 320 | for (int i = 0; i < ZAP_LEAF_ARRAY_BYTES && len > 0; i++) { |
| 321 | value = (value << 8) | la->la_array[i]; |
| 322 | byten++; |
| 323 | if (byten == array_int_len) { |
| 324 | stv(buf_int_len, p, value); |
| 325 | byten = 0; |
| 326 | len--; |
| 327 | if (len == 0) |
| 328 | return; |
| 329 | p += buf_int_len; |
| 330 | } |
| 331 | } |
| 332 | chunk = la->la_next; |
| 333 | } |
| 334 | } |
| 335 |
no test coverage detected