REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::detail::dynamic_storage Struct Reference

Storage policy backing real::regex: heap, sized once at run time. More...

#include <storage.hpp>

Collaboration diagram for real::detail::dynamic_storage:
[legend]

Classes

struct  state_type
 VM scratch state: SBO thread lists, working slots and eps stack. More...
 

Public Types

using name_owner = name_context_box
 Name-resolution owner: empty unless the result outlives the regex it came from.
 
using slot_storage = small_vec< std::size_t, 32 >
 Capture-slot container: SBO, avoiding the heap for typical small group counts.
 

Public Member Functions

constexpr program_view view () const
 Returns a non-owning view of the compiled program.
 
constexpr std::string_view pattern () const
 Returns the original pattern text.
 
constexpr flags compiled_flags () const
 Returns the flag set in force: constructor flags, plus a leading global-flags group's additions, minus its -removal – see real::basic_regex::compile_flags.
 

Static Public Member Functions

static constexpr dynamic_storage compile (std::string_view pattern, flags compile_flags)
 Parses and compiles pattern with flags compile_flags.
 

Public Attributes

std::string pattern_text
 The original pattern text.
 
dynamic_program program
 The compiled program.
 
flags effective_flags {flags::none}
 Constructor flags merged with any leading (?imsxaU) group.
 
detail::regex_immutables immut_ {}
 Per-regex lazy-DFA/one-pass cache, built under program-identity invalidation (thread-safe) and shared by every search on this regex — not rebuilt per find_iter. mutable: a const regex fills it on first routed search. Copy/move leave a fresh unbuilt cache; assignment invalidates built_for so assign-onto-warmed rebuilds (see detail::regex_immutables).
 

Static Public Attributes

static constexpr bool is_compile_time {}
 Selects the runtime constructor.
 

Detailed Description

Storage policy backing real::regex: heap, sized once at run time.

Match scratch uses small-buffer-optimized containers, so the common small-group match runs without a heap allocation.

Member Function Documentation

◆ compile()

static constexpr dynamic_storage real::detail::dynamic_storage::compile ( std::string_view  pattern,
flags  compile_flags 
)
inlinestaticconstexpr

Parses and compiles pattern with flags compile_flags.

Parameters
[in]patternThe pattern text.
[in]compile_flagsThe requested flags (merged with a leading (?imsxaU) / (?flags-flags) group).
Returns
A populated storage object.
Exceptions
real::regex_erroron an invalid or over-limit pattern.

◆ compiled_flags()

constexpr flags real::detail::dynamic_storage::compiled_flags ( ) const
inlineconstexpr

Returns the flag set in force: constructor flags, plus a leading global-flags group's additions, minus its -removal – see real::basic_regex::compile_flags.

Returns
The effective flag set.

◆ pattern()

constexpr std::string_view real::detail::dynamic_storage::pattern ( ) const
inlineconstexpr

Returns the original pattern text.

Returns
The pattern, valid as long as this storage is alive.

◆ view()

constexpr program_view real::detail::dynamic_storage::view ( ) const
inlineconstexpr

Returns a non-owning view of the compiled program.

Note
Returning by value here is deliberate, and the alternatives are priced. The compile-time storage hands back a reference and explains why; this one builds the view per call, and view() runs once per search(). Two ways to remove that were prototyped and refused, each on its own ground:
  • Materialise the view behind an identity guard, so the construction happens once per program. It enlarges every regex object by the size of a view, which is the wrong direction for anyone holding many patterns, and the guard is subtler than it looks: a MOVE leaves program.code.data() unchanged, so a guard testing only the program's identity validates a view still pointing into the moved-from object. The obvious one-condition form aborts the lifetime tests as a double free; a correct guard must also test view_.immut != &immut_.
  • Carry pattern_hints by pointer instead of copying it into the view. This shrinks the construction rather than removing it, so it can win at most a fraction of what removing it wins – against an indirection on every hot hint read, at every site that reads one.

The whole prize is a few nanoseconds per search, and both standing proposals were competing for that same budget. The dynamic path's real gap to the compile-time one is several times larger than the prize, so most of it is somewhere else entirely.

Returns
The view; valid as long as this storage is alive.

The documentation for this struct was generated from the following file: