WP_Token_Map::from_precomputed_table( array $state ): WP_Token_Map

In this article

Creates a token map from a pre-computed table.

Description

This skips the initialization cost of generating the table.

This function should only be used to load data created with WP_Token_Map::precomputed_php_source_tag().

Parameters

$statearrayrequired
Stores pre-computed state for directly loading into a Token Map.
  • storage_version string
    Which version of the code produced this state.
  • key_length int
    Group key length.
  • groups string
    Group lookup index.
  • large_words array
    Large word groups and packed strings.
  • small_words string
    Small words packed string.
  • small_mappings array
    Small word mappings.

Return

WP_Token_Map Map with precomputed data loaded.

Source

public static function from_precomputed_table( $state ): ?WP_Token_Map {
	$has_necessary_state = isset(
		$state['storage_version'],
		$state['key_length'],
		$state['groups'],
		$state['large_words'],
		$state['small_words'],
		$state['small_mappings']
	);

	if ( ! $has_necessary_state ) {
		_doing_it_wrong(
			__METHOD__,
			__( 'Missing required inputs to pre-computed WP_Token_Map.' ),
			'6.6.0'
		);
		return null;
	}

	if ( self::STORAGE_VERSION !== $state['storage_version'] ) {
		_doing_it_wrong(
			__METHOD__,
			/* translators: 1: version string, 2: version string. */
			sprintf( __( 'Loaded version \'%1$s\' incompatible with expected version \'%2$s\'.' ), $state['storage_version'], self::STORAGE_VERSION ),
			'6.6.0'
		);
		return null;
	}

	$map = new WP_Token_Map();

	$map->key_length     = $state['key_length'];
	$map->groups         = $state['groups'];
	$map->large_words    = $state['large_words'];
	$map->small_words    = $state['small_words'];
	$map->small_mappings = $state['small_mappings'];

	return $map;
}

Changelog

VersionDescription
6.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.