Text_Diff_Renderer_inline::_changed( $orig, $final )
- Source
wp-includes/Text/Diff/Renderer/inline.php:132
Compatibility
- WordPress
- core
- 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
$orig$final
Performance profile
How much work a call to Text_Diff_Renderer_inline::_changed() 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
- Scaling
- Scales with input
- Instructions
- 13–51
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 114.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- regexregular expression over the whole input
preg_split()called directly
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 Text_Diff_Renderer_inline::_changed() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 13–35 | ->_deleted(), ->_added() |
| always | 49–50 | ->_splitOnWords(), ->_splitOnWords(), ->getParams(), split_level(), array_merge(), ->render() |
| always | 50–51 | preg_split(), preg_split(), ->getParams(), split_level(), array_merge(), ->render() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 114 | 13–51 | 8 | |
| 8.5 | 114 | 13–51 | 8 | |
| 8.4 | 114 | 13–51 | 8 | 26 fewer instructions than PHP 8.3 |
| 8.3 | 140 | 13–62 | 8 | |
| 8.2 | 140 | 13–62 | 8 | |
| 8.1 | 140 | 13–62 | 8 | |
| 7.4 | 140 | 13–62 | 8 |
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.
Uses · 6
- Text_Diff_Renderer_inline::_deleted()
- Text_Diff_Renderer_inline::_added()
- Text_Diff::__construct()Computes diffs between sequences of strings.
- Text_Diff_Renderer_inline::_splitOnWords()
- Text_Diff_Renderer_inline::__construct()
- Text_Diff_Renderer_inline::getParams()
Source code
function _changed($orig, $final) { /* If we've already split on characters, just display. */ if ($this->_split_level == 'characters') { return $this->_deleted($orig) . $this->_added($final); } /* If we've already split on words, just display. */ if ($this->_split_level == 'words') { $prefix = ''; while ($orig[0] !== false && $final[0] !== false && substr($orig[0], 0, 1) == ' ' && substr($final[0], 0, 1) == ' ') { $prefix .= substr($orig[0], 0, 1); $orig[0] = substr($orig[0], 1); $final[0] = substr($final[0], 1); } return $prefix . $this->_deleted($orig) . $this->_added($final); } $text1 = implode("\n", $orig); $text2 = implode("\n", $final); /* Non-printing newline marker. */ $nl = "\0"; if ($this->_split_characters) { $diff = new Text_Diff('native', array(preg_split('//', $text1), preg_split('//', $text2))); } else { /* We want to split on word boundaries, but we need to preserve * whitespace as well. Therefore we split on words, but include * all blocks of whitespace in the wordlist. */ $diff = new Text_Diff('native', array($this->_splitOnWords($text1, $nl), $this->_splitOnWords($text2, $nl))); } /* Get the diff in inline format. */ $renderer = new Text_Diff_Renderer_inline (array_merge($this->getParams(), array('split_level' => $this->_split_characters ? 'characters' : 'words'))); /* Run the diff and get the output. */ return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; }Changelog
Unchanged from 6.7.7 through 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/Text/Diff/Renderer/inline.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.