wppaste
WordPress

WP_Token_Map::read_small_token( string $text, int $offset = 0, $matched_token_byte_length = null, string $case_sensitivity = 'case-sensitive' ): string|null

Since
6.6.0
Source
wp-includes/class-wp-token-map.php:595
Finds a match for a short word at the index.

Compatibility

WordPress
since 6.6.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$textstring
String in which to search for a lookup key.
$offsetintoptional
How many bytes into the string where the lookup key ought to start. Default 0.Default: 0
$matched_token_byte_lengthoptional
Default: null
$case_sensitivitystringoptional
Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'.Default: 'case-sensitive'

Return value

string|null
Mapped value of lookup key if found, otherwise null.

Performance profile

How much work a call to WP_Token_Map::read_small_token() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
17–50

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 84.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Token_Map::read_small_token() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$case_sensitivity !== "ascii-case-insensitive"17–38none
$case_sensitivity === "ascii-case-insensitive"21–46strtoupper()
$case_sensitivity === "ascii-case-insensitive" && $at45–50strtoupper(), strtoupper()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8417–5010
8.58417–5010
8.48417–50104 fewer instructions than PHP 8.3
8.38821–5410
8.28821–5410
8.18821–5410
7.48821–5410

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Used by · 1

  • WP_Token_Map::read_token()If the text starting at a given offset is a lookup key in the map, return the corresponding transformation from the map, else `false`.

Source code

	private function read_small_token( string $text, int $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ): ?string {		$ignore_case  = 'ascii-case-insensitive' === $case_sensitivity;		$small_length = strlen( $this->small_words );		$search_text  = substr( $text, $offset, $this->key_length );		if ( $ignore_case ) {			$search_text = strtoupper( $search_text );		}		$starting_char = $search_text[0]; 		$at = 0;		while ( $at < $small_length ) {			if (				$starting_char !== $this->small_words[ $at ] &&				( ! $ignore_case || strtoupper( $this->small_words[ $at ] ) !== $starting_char )			) {				$at += $this->key_length + 1;				continue;			} 			for ( $adjust = 1; $adjust < $this->key_length; $adjust++ ) {				if ( "\x00" === $this->small_words[ $at + $adjust ] ) {					$matched_token_byte_length = $adjust;					return $this->small_mappings[ $at / ( $this->key_length + 1 ) ];				} 				if (					$search_text[ $adjust ] !== $this->small_words[ $at + $adjust ] &&					( ! $ignore_case || strtoupper( $this->small_words[ $at + $adjust ] !== $search_text[ $adjust ] ) )				) {					$at += $this->key_length + 1;					continue 2;				}			} 			$matched_token_byte_length = $adjust;			return $this->small_mappings[ $at / ( $this->key_length + 1 ) ];		} 		return null;	}

Changelog

Introduced in 6.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-token-map.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.