-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WP_HTML_Tag_Processor: Inject dynamic data to block HTML markup in PHP #42485
Changes from 15 commits
4887c5c
3f148db
6d089f2
2dbfa03
fadd51b
17879e8
bdd56a6
8a48fab
e9a71d6
9bcfd3a
f6d1bcc
541d86b
cdd8ae0
1852cf7
6c4647d
4554dd3
e2eb423
68b55c4
f664c08
147647b
d8b8ddd
a325fa3
a4fb703
c017420
07041ee
63f4e34
1021d9b
e0910be
273c502
19a8546
c96f08b
218afe4
81d43e2
53143f8
bddc2db
f299bf0
13c3270
5c2d080
509684c
d9d3bab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* HTML Walker: Attribute token structure class. | ||
* | ||
* @package WordPress | ||
* @subpackage HTML | ||
* @since 6.1.0 | ||
*/ | ||
|
||
/** | ||
* Data structure for the attribute token that allows to drastically improve performance. | ||
* | ||
* @since 6.1.0 | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @see WP_HTML_Walker | ||
*/ | ||
class WP_HTML_Attribute_Token { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please lock down this code so it is not accessible from plugins or other parts of WordPress. It should only be used for the cases described in this PR. |
||
/** | ||
* Attribute name. | ||
* | ||
* @since 6.1.0 | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* Attribute value. | ||
* | ||
* @since 6.1.0 | ||
* @var int | ||
*/ | ||
public $value_starts_at; | ||
|
||
/** | ||
* How many bytes the value occupies in the input HTML. | ||
* | ||
* @since 6.1.0 | ||
* @var int | ||
*/ | ||
public $value_length; | ||
|
||
/** | ||
* The string offset where the attribute name starts. | ||
* | ||
* @since 6.1.0 | ||
* @var int | ||
*/ | ||
public $start; | ||
|
||
/** | ||
* The string offset after the attribute value or its name. | ||
* | ||
* @since 6.1.0 | ||
* @var int | ||
*/ | ||
public $end; | ||
|
||
/** | ||
* Whether the attribute is a boolean attribute with value `true`. | ||
* | ||
* @since 6.1.0 | ||
* @var bool | ||
*/ | ||
public $is_true; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 6.1.0 | ||
* | ||
* @param string $name Attribute name. | ||
* @param integer $value_start Attribute value. | ||
* @param integer $value_length Number of bytes attribute value spans. | ||
* @param integer $start The string offset where the attribute name starts. | ||
* @param integer $end The string offset after the attribute value or its name. | ||
* @param boolean $is_true Whether the attribute is a boolean attribute with true value. | ||
dmsnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public function __construct( $name, $value_start, $value_length, $start, $end, $is_true ) { | ||
$this->name = $name; | ||
$this->value_starts_at = $value_start; | ||
$this->value_length = $value_length; | ||
$this->start = $start; | ||
$this->end = $end; | ||
$this->is_true = $is_true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* HTML Walker: Text replacement class. | ||
* | ||
* @package WordPress | ||
* @subpackage HTML | ||
* @since 6.1.0 | ||
*/ | ||
|
||
/** | ||
* Data structure used to replace existing content from start to end that allows to drastically improve performance. | ||
* | ||
* @since 6.1.0 | ||
adamziel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @see WP_HTML_Walker | ||
*/ | ||
class WP_HTML_Text_Replacement { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, please change so this code is not accessible. |
||
/** | ||
* Byte offset into document where replacement span begins. | ||
* | ||
* @since 6.1.0 | ||
* @var int | ||
*/ | ||
public $start; | ||
|
||
/** | ||
* Byte offset into document where replacement span ends. | ||
* | ||
* @since 6.1.0 | ||
* @var int | ||
*/ | ||
public $end; | ||
|
||
/** | ||
* Span of text to insert in document to replace existing content from start to end. | ||
* | ||
* @since 6.1.0 | ||
* @var string | ||
*/ | ||
public $text; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 6.1.0 | ||
* | ||
* @param integer $start Byte offset into document where replacement span begins. | ||
* @param integer $end Byte offset into document where replacement span ends. | ||
* @param string $text Span of text to insert in document to replace existing content from start to end. | ||
dmsnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public function __construct( $start, $end, $text ) { | ||
$this->start = $start; | ||
$this->end = $end; | ||
$this->text = $text; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamziel and @dmsnell, is the note about the performance implications valid? Should we also include the same note for
WP_Class_Name_Update
andWP_Text_Replacement
? I know you discussed that extensively, but I'm not sure which part made the biggest difference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is valid, I think in @dmsnell's testing it reduced memory usage by like 90% compared to
array()
which sounds almost unbelievable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can update these comments across the board.
array()
was surprisingly terribly inefficient with memory use.