Ada 4.1.1
Fast spec-compliant URL parser
Loading...
Searching...
No Matches
url_pattern_list-inl.h
Go to the documentation of this file.
1
11#ifndef ADA_URL_PATTERN_LIST_INL_H
12#define ADA_URL_PATTERN_LIST_INL_H
13
14#include "ada/common_defs.h"
16#include "ada/url_pattern-inl.h"
19
20#include <bit>
21#include <cstdint>
22#include <cstring>
23#include <optional>
24#include <string>
25#include <string_view>
26#include <utility>
27#include <vector>
28
29#if ADA_NEON
30#include <arm_neon.h>
31#endif
32
33#if ADA_INCLUDE_URL_PATTERN
34namespace ada::url_pattern_list_detail {
35
36// ---- byte helpers ----------------------------------------------------------
37
38// Unaligned 8-byte little-endian load; all 8 bytes must be readable. The
39// byte-assembly fallback keeps big-endian targets correct (the compiler
40// lowers it to a single load plus byte swap).
41ada_really_inline uint64_t load8_le(const char* p) noexcept {
42 if constexpr (std::endian::native == std::endian::little) {
43 uint64_t x;
44 std::memcpy(&x, p, 8);
45 return x;
46 } else {
47 uint64_t x = 0;
48 for (uint32_t j = 0; j < 8; j++) {
49 x |= static_cast<uint64_t>(static_cast<uint8_t>(p[j])) << (8 * j);
50 }
51 return x;
52 }
53}
54
55// Bytes [0, n) of p packed little-endian, zero-padded; reads exactly n
56// bytes (n < 8). This is the byte-compare path for short tails.
57ada_really_inline uint64_t gather_le(const char* p, uint32_t n) noexcept {
58 uint64_t x = 0;
59 for (uint32_t j = 0; j < n; j++) {
60 x |= static_cast<uint64_t>(static_cast<uint8_t>(p[j])) << (8 * j);
61 }
62 return x;
63}
64
65// Mask selecting the low n bytes, 1 <= n <= 7.
66constexpr uint64_t low_bytes_mask(uint32_t n) noexcept {
67 return ~0ull >> (64 - 8 * n);
68}
69
70// ASCII case folding of n bytes from src into dst (the compiler vectorizes
71// this loop). Only ASCII letters change: canonical pathnames are ASCII, and
72// this is what a case-insensitive regular expression does over them.
73inline void ascii_fold(const char* src, uint32_t n, char* dst) noexcept {
74 for (uint32_t i = 0; i < n; i++) {
75 const uint8_t c = static_cast<uint8_t>(src[i]);
76 dst[i] = static_cast<char>(c | ((c >= 'A' && c <= 'Z') ? 0x20u : 0u));
77 }
78}
79
80// ---- witness machinery -----------------------------------------------------
81// Projection dispatch for wide trie nodes. A witness id names a feature of a
82// byte string:
83// 0..7 the byte at absolute offset id (0 when out of range)
84// 8..15 the byte at offset id-8 counted from the end
85// A projection is three witness bytes plus the length packed into one
86// uint64; a perfect multiplier turns it into a slot index. Builder and
87// matcher call the same accessors and the same packing, so a slot table
88// cannot disagree with the gather that reads it.
89
90constexpr uint8_t length_byte(uint32_t len) noexcept {
91 return len < 255u ? static_cast<uint8_t>(len) : static_cast<uint8_t>(255);
92}
93
94constexpr uint8_t witness_byte(const char* p, uint32_t len,
95 uint8_t id) noexcept { // ids 0..15
96 uint32_t o = id & 7u;
97 bool in = o < len;
98 uint32_t pos = (id & 8u) ? len - 1u - o : o; // wraps when !in; masked then
99 pos = in ? pos : 0u;
100 uint8_t v = len ? static_cast<uint8_t>(p[pos]) : static_cast<uint8_t>(0);
101 return in ? v : static_cast<uint8_t>(0);
102}
103
104constexpr uint64_t pack_projection(uint8_t f0, uint8_t f1, uint8_t f2,
105 uint8_t f3) noexcept {
106 return (static_cast<uint64_t>(f0) << 24) | (static_cast<uint64_t>(f1) << 16) |
107 (static_cast<uint64_t>(f2) << 8) | static_cast<uint64_t>(f3);
108}
109
110// Perfect-multiplier slot index; b <= 12 everywhere, so the shift is in
111// range and the product needs no modulus.
112constexpr uint64_t slot_of(uint64_t proj, uint64_t multiplier,
113 uint8_t b) noexcept {
114 return (proj * multiplier) >> (64 - b);
115}
116
117// Fixed-shape projection of one string: always 3 witness bytes plus the
118// length. Duplicated ids add no information but keep the gather uniform.
119constexpr uint64_t project(const char* p, uint32_t len,
120 uint16_t plan) noexcept {
121 return pack_projection(
122 witness_byte(p, len, static_cast<uint8_t>(plan & 15u)),
123 witness_byte(p, len, static_cast<uint8_t>((plan >> 4) & 15u)),
124 witness_byte(p, len, static_cast<uint8_t>((plan >> 8) & 15u)),
125 length_byte(len));
126}
127
128// ---- segment scan ----------------------------------------------------------
129
130// Splits the pathname into segments in one pass, in place: only segment
131// starts are recorded, with a sentinel soff[nseg] = ulen + 1 so that
132// seg_len(i) == soff[i + 1] - soff[i] - 1. Returns the segment count, or 0
133// when the input has more than max_fast_path_segments segments (the caller
134// falls back to the sequential matcher). Requires ulen >= 1 and
135// url[0] == '/'.
136//
137// Two implementations with the same contract: the portable SWAR scan (8
138// bytes per step, an exact zero-byte test on x ^ '/'-fill with no false
139// positives, bytes >= 0x80 included, and a byte-exact partial load for the
140// tail, so the input is never over-read), and on AArch64 a NEON scan for
141// inputs of 16 bytes or more (16 bytes per step, the '/' compare narrowed
142// to one nibble per byte, the last block overlapping the previous one so
143// the input is never over-read). The 1k+ pathname benchmark in the PR
144// discussion is what keeps the NEON scan: it is faster at every length and
145// 3-4x faster past 1 KB.
146struct segment_emitter {
147 uint16_t* soff;
148 uint32_t nseg = 0;
149 uint32_t start = 1;
150 // One segment start per set bit of `lanes`; a lane is 1 << shift bits
151 // wide (8 for the SWAR masks, 4 for the NEON nibble masks).
152 ada_really_inline bool emit(uint64_t lanes, uint32_t base,
153 unsigned shift) noexcept {
154 using url_pattern_list_limits::max_fast_path_segments;
155 while (lanes) {
156 const uint32_t pos =
157 base + (static_cast<uint32_t>(std::countr_zero(lanes)) >> shift);
158 if (nseg >= max_fast_path_segments) {
159 return false;
160 }
161 soff[nseg++] = static_cast<uint16_t>(start);
162 start = pos + 1;
163 lanes &= lanes - 1;
164 }
165 return true;
166 }
167 ada_really_inline uint32_t finish(uint32_t ulen) noexcept {
168 using url_pattern_list_limits::max_fast_path_segments;
169 if (nseg >= max_fast_path_segments) {
170 return 0;
171 }
172 soff[nseg++] = static_cast<uint16_t>(start);
173 soff[nseg] = static_cast<uint16_t>(ulen + 1); // sentinel
174 return nseg;
175 }
176};
177
178ada_really_inline uint32_t scan_segments_swar(const char* url, uint32_t ulen,
179 uint16_t* soff) noexcept {
180 constexpr uint64_t slashes = 0x2F2F2F2F2F2F2F2Full;
181 constexpr uint64_t low7 = 0x7F7F7F7F7F7F7F7Full;
182 // Bit 7 of every byte of x that is zero, exactly: (b & 0x7F) + 0x7F has
183 // bit 7 set iff the low bits are non-zero, b itself has it set iff b is
184 // >= 0x80, and no lane can carry into its neighbour.
185 const auto zero_lanes = [](uint64_t x) noexcept {
186 return ~(((x & low7) + low7) | x | low7);
187 };
188 segment_emitter out{soff};
189 uint32_t i = 1;
190 for (; i + 8 <= ulen; i += 8) {
191 const uint64_t lanes = zero_lanes(load8_le(url + i) ^ slashes);
192 if (lanes != 0 && !out.emit(lanes, i, 3)) {
193 return 0;
194 }
195 }
196 if (i < ulen) { // tail of 1..7 bytes: zero padding is never a '/'
197 const uint64_t lanes = zero_lanes(gather_le(url + i, ulen - i) ^ slashes);
198 if (lanes != 0 && !out.emit(lanes, i, 3)) {
199 return 0;
200 }
201 }
202 return out.finish(ulen);
203}
204
205#if ADA_NEON
206ada_really_inline uint32_t scan_segments_neon(const char* url, uint32_t ulen,
207 uint16_t* soff) noexcept {
208 // Requires ulen >= 16.
209 const uint8x16_t slash = vdupq_n_u8('/');
210 // One bit per byte lane that holds a '/': compare, narrow each 16-bit
211 // pair to its high nibble, keep bit 0 of every nibble.
212 const auto slash_lanes = [&](const char* p) noexcept {
213 const uint8x16_t v = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
214 const uint64_t nibbles =
215 vget_lane_u64(vreinterpret_u64_u8(vshrn_n_u16(
216 vreinterpretq_u16_u8(vceqq_u8(v, slash)), 4)),
217 0);
218 return nibbles & 0x1111111111111111ull;
219 };
220 segment_emitter out{soff};
221 uint32_t i = 0;
222 for (; i + 16 <= ulen; i += 16) {
223 uint64_t lanes = slash_lanes(url + i);
224 if (i == 0) {
225 lanes &= ~0xFull; // the leading '/' is not a separator
226 }
227 if (lanes != 0 && !out.emit(lanes, i, 2)) {
228 return 0;
229 }
230 }
231 if (i < ulen) { // overlapped last block: drop the lanes already scanned
232 const uint32_t off = ulen - 16;
233 const uint64_t lanes = slash_lanes(url + off) & (~0ull << ((i - off) * 4));
234 if (lanes != 0 && !out.emit(lanes, off, 2)) {
235 return 0;
236 }
237 }
238 return out.finish(ulen);
239}
240#endif // ADA_NEON
241
242ada_really_inline uint32_t scan_segments(const char* url, uint32_t ulen,
243 uint16_t* soff) noexcept {
244#if ADA_NEON
245 if (ulen >= 16) {
246 return scan_segments_neon(url, ulen, soff);
247 }
248#endif
249 return scan_segments_swar(url, ulen, soff);
250}
251
252// ---- verify / dispatch -----------------------------------------------------
253
254// One input segment prepared for dispatch: its bytes, its length, and how
255// many bytes are readable from p (to the end of the pathname).
256struct segment_ref {
257 const char* p;
258 uint32_t len;
259 uint32_t avail;
260};
261
262// Segment-vs-edge compare. Keys of 8..16 bytes verify from two whole-word
263// loads inside the segment; shorter keys from one masked load when the
264// input has 8 readable bytes, else from a byte gather (short tails such as
265// "42" or "me"); longer keys through memcmp against the blob. An empty key
266// (a pattern such as "/users/") matches exactly the empty segment.
267ada_really_inline bool verify_edge(const edge_record& e, const segment_ref& s,
268 const char* blob) noexcept {
269 const uint32_t len = s.len;
270 if (len != e.key_length) {
271 return false;
272 }
273 if (len == 0) {
274 return true;
275 }
276 if (len > 16) {
277 return std::memcmp(s.p, blob + e.key_offset, len) == 0;
278 }
279 if (len >= 8) {
280 return ((load8_le(s.p) ^ e.prefix) |
281 (load8_le(s.p + len - 8) ^ e.suffix)) == 0;
282 }
283 const uint64_t x = s.avail >= 8 ? (load8_le(s.p) & low_bytes_mask(len))
284 : gather_le(s.p, len);
285 return x == e.prefix;
286}
287
288// The typed view of the arena the walk reads; derived once per match.
289struct table_view {
290 const node_record* nodes;
291 const hash_record* hashes;
292 const edge_record* edges;
293 const uint8_t* slots;
294 const char* blob;
295 const uint16_t* root_index;
296};
297
298ada_really_inline table_view view_of(const compiled_routes& r) noexcept {
299 return table_view{r.section<node_record>(r.nodes_offset),
300 r.section<hash_record>(r.hashes_offset),
301 r.section<edge_record>(r.edges_offset),
302 r.section<uint8_t>(r.slots_offset),
303 r.section<char>(r.blob_offset),
304 r.section<uint16_t>(r.root_index_offset)};
305}
306
307// Static-child dispatch: returns the child ordinal within the node or -1.
308// Correctness never depends on the projection or the index: the candidate
309// is always confirmed by a full segment compare, so a bad table can only
310// cost time, never change an answer.
311ada_really_inline int32_t dispatch_static(const table_view& t,
312 const node_record& nd,
313 const segment_ref& s) noexcept {
314 const edge_record* e = t.edges + nd.first_child;
315 switch (nd.dispatch) {
316 case 0:
317 return -1;
318 case 1: { // direct: up to 8 compares, each gated by the key length
319 for (uint32_t j = 0; j < nd.n_static; j++) {
320 if (verify_edge(e[j], s, t.blob)) {
321 return static_cast<int32_t>(j);
322 }
323 }
324 return -1;
325 }
326 case 2: { // projection: gather -> multiply -> slot -> verify
327 const hash_record& h = t.hashes[nd.hash_index];
328 const uint64_t proj = project(s.p, s.len, h.witness_plan);
329 const uint8_t ord =
330 t.slots[h.slot_base + slot_of(proj, h.multiplier, h.slot_bits)];
331 if (ord == 0xFF) {
332 return -1;
333 }
334 return verify_edge(e[ord], s, t.blob) ? static_cast<int32_t>(ord) : -1;
335 }
336 case 4: { // root first-byte index: jump to the run of children that
337 // share the segment's first byte (children are sorted by it)
338 if (s.len == 0) {
339 return -1; // no first byte; an indexed root has no empty key
340 }
341 const uint8_t b = static_cast<uint8_t>(s.p[0]);
342 uint32_t j = t.root_index[b];
343 if (j == 0xFFFF) {
344 return -1;
345 }
346 for (; j < nd.n_static && static_cast<uint8_t>(e[j].prefix & 0xFFu) == b;
347 j++) {
348 if (verify_edge(e[j], s, t.blob)) {
349 return static_cast<int32_t>(j);
350 }
351 }
352 return -1;
353 }
354 default: { // linear demotion rung (also carries fanout > 254)
355 for (uint32_t j = 0; j < nd.n_static; j++) {
356 if (verify_edge(e[j], s, t.blob)) {
357 return static_cast<int32_t>(j);
358 }
359 }
360 return -1;
361 }
362 }
363}
364
365// ---- the match residual ----------------------------------------------------
366
367// Matches `pathname` against the compiled tables. When the input is out of
368// the fast-path contract, returns with within_fast_path == false and no
369// answer; the caller falls back to the sequential matcher.
370ada_really_inline void match_compiled(const compiled_routes& r, const char* url,
371 uint32_t ulen,
372 engine_result& out) noexcept {
373 using url_pattern_list_limits::max_fast_path_pathname_length;
374 using url_pattern_list_limits::max_fast_path_segments;
375 out = engine_result{};
376 if (ulen == 0 || url[0] != '/' || ulen > max_fast_path_pathname_length) {
377 out.within_fast_path = false; // the sequential fallback decides
378 return;
379 }
380 const table_view t = view_of(r);
381 const route_record* routes = r.section<route_record>(r.routes_offset);
382
383 // Segment scan; overflow means the input is beyond the fast path.
384 uint16_t soff[max_fast_path_segments + 1];
385 const uint32_t nseg = scan_segments(url, ulen, soff);
386 if (nseg == 0) {
387 out.within_fast_path = false;
388 return;
389 }
390 const auto seg_len = [&](uint32_t i) {
391 return static_cast<uint32_t>(soff[i + 1]) - soff[i] - 1u;
392 };
393 const auto seg_ref = [&](uint32_t i) {
394 const uint32_t off = soff[i];
395 return segment_ref{url + off, seg_len(i), ulen - off};
396 };
397
398 // Trie walk with an explicit bounded backtrack stack. Every node offers
399 // the same three alternatives in the compiled priority order (static
400 // child, param child, wildcard); a backtrack record stores the resume
401 // point, and a record is pushed only when the node still has an untried
402 // alternative, so the stack never exceeds the walk depth. Edges encoded
403 // as -2 - route are pure-leaf shortcuts.
404 enum alternative : uint16_t {
405 alt_static = 0,
406 alt_param = 1,
407 alt_wild = 2,
408 alt_none = 3
409 };
410 struct backtrack {
411 int32_t node;
412 uint16_t i;
413 uint16_t resume;
414 };
415 backtrack stack[max_fast_path_segments + 1];
416 uint32_t sp = 0;
417 int32_t node = 0;
418 uint32_t i = 0;
419 uint32_t alt = alt_static;
420 int32_t route = -1;
421 uint32_t wild_from = 0;
422 bool wild = false;
423 for (;;) {
424 const node_record& nd = t.nodes[static_cast<size_t>(node)];
425 if (alt == alt_static) {
426 if (i == nseg) {
427 if (nd.terminal_route >= 0) {
428 route = nd.terminal_route;
429 break;
430 }
431 alt = alt_none;
432 } else {
433 const int32_t ord = dispatch_static(t, nd, seg_ref(i));
434 if (ord >= 0) {
435 const int32_t nxt = t.edges[static_cast<size_t>(nd.first_child) +
436 static_cast<size_t>(ord)]
437 .node;
438 if (nxt >= 0) {
439 if (nd.has_alternative) {
440 stack[sp++] = {node, static_cast<uint16_t>(i), alt_param};
441 }
442 node = nxt;
443 i++;
444 continue;
445 }
446 // Pure-leaf shortcut.
447 if (i + 1 == nseg) {
448 route = -2 - nxt;
449 break;
450 }
451 alt = alt_param; // dead end: fall through to this node's fallbacks
452 } else {
453 alt = alt_param;
454 }
455 }
456 }
457 if (alt == alt_param) {
458 const int32_t pc = nd.param_child;
459 if (pc != -1 && seg_len(i) > 0) {
460 if (pc >= 0) {
461 if (nd.wild_route >= 0) {
462 stack[sp++] = {node, static_cast<uint16_t>(i), alt_wild};
463 }
464 node = pc;
465 i++;
466 alt = alt_static;
467 continue;
468 }
469 // Pure-leaf param shortcut.
470 if (i + 1 == nseg) {
471 route = -2 - pc;
472 break;
473 }
474 alt = alt_wild; // only the wildcard remains here
475 } else {
476 alt = alt_wild;
477 }
478 }
479 if (alt == alt_wild) {
480 if (nd.wild_route >= 0 &&
481 wildcard_tail_ok(url + soff[i], ulen - soff[i])) {
482 route = nd.wild_route;
483 wild_from = i;
484 wild = true;
485 break;
486 }
487 // No alternative left at this node: resume from the backtrack stack
488 // (alt is overwritten by the popped record).
489 }
490 if (sp == 0) {
491 break; // nothing to resume: miss
492 }
493 --sp;
494 node = stack[sp].node;
495 i = stack[sp].i;
496 alt = stack[sp].resume;
497 }
498
499 out.route = route;
500 if (route >= 0) { // capture extraction: params first, wildcard tail last
501 const route_record& rm = routes[static_cast<size_t>(route)];
502 uint32_t nc = 0;
503 for (uint32_t k = 0; k < rm.n_params; k++) {
504 const uint32_t p = rm.param_positions[k];
505 out.captures[nc++] = {soff[p], seg_len(p)};
506 }
507 if (wild) {
508 out.captures[nc++] = {soff[wild_from], ulen - soff[wild_from]};
509 }
510 out.capture_count = nc;
511 }
512}
513
514} // namespace ada::url_pattern_list_detail
515
516namespace ada {
517
518template <url_pattern_regex::regex_concept regex_provider>
519tl::expected<url_pattern_list<regex_provider>, errors>
520url_pattern_list<regex_provider>::create(
521 std::vector<std::string>&& pathname_patterns, bool ignore_case) {
522 url_pattern_list list{};
523 list.patterns_ = std::move(pathname_patterns);
524 auto compiled = url_pattern_list_detail::compile_pathname_patterns(
525 list.patterns_, ignore_case);
526 if (!compiled) {
527 return tl::unexpected(compiled.error());
528 }
529 list.compiled_ = std::move(*compiled);
530 return list;
531}
532
533template <url_pattern_regex::regex_concept regex_provider>
534void url_pattern_list<regex_provider>::consider_route(
535 uint32_t route_index, std::string_view pathname, std::string_view probe,
536 bool fold_input, url_pattern_list_detail::engine_result& best,
537 std::vector<std::optional<std::string>>& best_groups) const {
538 namespace detail = url_pattern_list_detail;
539 const detail::route_record* routes =
540 compiled_.section<detail::route_record>(compiled_.routes_offset);
541 const detail::route_record& candidate = routes[route_index];
542 // Only test candidates that would outrank the current best.
543 if (best.route >= 0) {
544 const detail::route_record& current =
545 routes[static_cast<size_t>(best.route)];
546 if (!detail::outranks(candidate.kind_sequence, candidate.kind_length,
547 route_index, current.kind_sequence,
548 current.kind_length,
549 static_cast<size_t>(best.route))) {
550 return;
551 }
552 }
553 if (candidate.mode == detail::route_mode::regexp) {
554 // A route whose certain segment shape does not fit the input cannot
555 // match at all: skip the provider.
556 if (!detail::match_regexp_shape(compiled_, route_index, probe,
557 fold_input)) {
558 return;
559 }
560 // URLPattern's own test/exec split: regex_match answers yes/no (this is
561 // what rejects a non-matching route cheaply; a regex_search miss can
562 // cost a scan over every start position), and regex_search then
563 // produces the group values exactly as url_pattern::exec does.
564 const url_pattern_component<regex_provider>& component =
565 regexp_components_[static_cast<size_t>(candidate.regexp_component)];
566 if (!component.fast_test(pathname)) {
567 return;
568 }
569 auto groups = component.fast_match(pathname);
570 if (groups) {
571 best = detail::engine_result{};
572 best.route = static_cast<int32_t>(route_index);
573 best_groups = std::move(*groups);
574 }
575 } else {
576 detail::engine_result scratch{};
577 if (detail::match_route_sequential(compiled_, route_index, probe,
578 fold_input, scratch)) {
579 scratch.route = static_cast<int32_t>(route_index);
580 best = scratch;
581 best_groups.clear();
582 }
583 }
584}
585
586template <url_pattern_regex::regex_concept regex_provider>
587url_pattern_list_match_result url_pattern_list<regex_provider>::match(
588 std::string_view pathname) const {
589 namespace detail = url_pattern_list_detail;
590 using url_pattern_list_limits::max_fast_path_pathname_length;
591 // A default-constructed list (or one compiled from no routes) has no
592 // tables. Walking them would dereference section pointers into an empty
593 // arena.
594 if (patterns_.empty() || compiled_.arena.empty()) {
595 return {};
596 }
597 // With ignore_case the compiled literals are ASCII-folded, so the fast
598 // path probes a folded copy of the input (offsets are unchanged, so the
599 // captures still slice the original). Inputs beyond the fast-path length
600 // are folded on the fly by the sequential matcher instead.
601 char folded[max_fast_path_pathname_length];
602 std::string_view probe = pathname;
603 bool fold_input = false;
604 if (compiled_.ignore_case) {
605 if (pathname.size() <= max_fast_path_pathname_length) {
606 detail::ascii_fold(pathname.data(),
607 static_cast<uint32_t>(pathname.size()), folded);
608 probe = std::string_view(folded, pathname.size());
609 } else {
610 fold_input = true;
611 }
612 }
613 detail::engine_result best{};
614 std::vector<std::optional<std::string>> best_groups{};
615 detail::match_compiled(compiled_, probe.data(),
616 static_cast<uint32_t>(probe.size()), best);
617 const uint32_t* aux = compiled_.section<uint32_t>(compiled_.aux_offset);
618 if (!best.within_fast_path) {
619 // The input exceeds a fast-path limit (length, segment count, or no
620 // leading '/'): the sequential fallback matches every route with
621 // identical priority semantics.
622 best = detail::engine_result{};
623 for (size_t i = 0; i < patterns_.size(); i++) {
624 consider_route(static_cast<uint32_t>(i), pathname, probe, fold_input,
625 best, best_groups);
626 }
627 } else if (best.route >= 0) {
628 // A fast-path winner is final except for the auxiliary routes recorded
629 // at creation as able to outrank it (usually none).
630 const detail::route_record& winner =
631 compiled_.section<detail::route_record>(
632 compiled_.routes_offset)[static_cast<size_t>(best.route)];
633 for (uint32_t k = 0; k < winner.challenger_count; k++) {
634 consider_route(aux[winner.challenger_first + k], pathname, probe,
635 fold_input, best, best_groups);
636 }
637 } else {
638 // A fast-path miss: any auxiliary route may still match.
639 for (uint32_t k = 0; k < compiled_.n_aux_all; k++) {
640 consider_route(aux[k], pathname, probe, fold_input, best, best_groups);
641 }
642 }
643 url_pattern_list_match_result result{};
644 result.route_index = best.route;
645 if (best.route >= 0) {
646 const detail::route_record& winner =
647 compiled_.section<detail::route_record>(
648 compiled_.routes_offset)[static_cast<size_t>(best.route)];
649 if (winner.mode == detail::route_mode::regexp) {
650 result.regexp_route = true;
651 result.regexp_groups = std::move(best_groups);
652 } else {
653 result.capture_count = best.capture_count;
654 result.captures_truncated = best.captures_truncated;
655 result.captures = best.captures;
656 }
657 }
658 return result;
659}
660
661} // namespace ada
662#endif // ADA_INCLUDE_URL_PATTERN
663#endif // ADA_URL_PATTERN_LIST_INL_H
Cross-platform compiler macros and common definitions.
#define ada_really_inline
Definition common_defs.h:85
constexpr int32_t base
errors
Error codes for URL parsing operations.
Definition errors.h:17
tl::expected< result_type, ada::errors > result
Declaration for the URLPattern inline functions.
Declaration for the URLPattern helpers.
Declaration for the URLPattern helpers.
Compiled set-level matching over URLPattern pathname patterns.