Skip to content

Commit bbd5775

Browse files
committed
Improved performance, thanks to @nikic's new regex.
1 parent 044ebd6 commit bbd5775

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/phpDocumentor/Reflection/DocBlock/LongDescription.php

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,35 @@ public function getParsedContents()
6262
if (null === $this->parsedContents) {
6363
$this->parsedContents = preg_split(
6464
'/\{
65-
# We want the whole tag line, but without the inline tag
66-
# delimiters.
65+
# "{@}" is not a valid inline tag. This ensures that
66+
# we do not treat it as one, but treat it literally.
67+
(?!@\})
68+
# We want to capture the whole tag line, but without the
69+
# inline tag delimiters.
6770
(\@
68-
# The content should not be captured, or it will appear
69-
# in the result separately.
71+
# Match everything up to the next delimiter.
72+
[^{}]*
73+
# Nested inline tag content should not be captured, or
74+
# it will appear in the result separately.
7075
(?:
7176
# Match nested inline tags.
72-
# Because we did not catch the tag delimiters
73-
# earlier, we must be explicit with them here.
74-
# Notice that this also matches "{}", as a way to
75-
# later introduce it as an escape sequence.
76-
\{(?1)?\}
77-
|
78-
# "{@}" is not a valid inline tag. This ensures that
79-
# having it occur inside an inline tag does not trip
80-
# us up. While this is required in any event, notice
81-
# that this is also later an escape sequence.
82-
\{\@\}
83-
|
84-
# If we are not dealing with a nested inline tag,
85-
# get the character, as long as it is not a closing
86-
# tag delimiter.
87-
# This is an alternative way of non-greedy matching.
88-
[^\}]
89-
)+ # We need to keep doing these checks for every
90-
# character, since we never know where an inline tag
91-
# is going to start at. The "+" ensures we are not
92-
# treating "{@}" as a valid inline tag.
77+
(?:
78+
# Because we did not catch the tag delimiters
79+
# earlier, we must be explicit with them here.
80+
# Notice that this also matches "{}", as a way
81+
# to later introduce it as an escape sequence.
82+
\{(?1)?\}
83+
|
84+
# Make sure we match hanging "{".
85+
\{
86+
)
87+
# Match content after the nested inline tag.
88+
[^{}]*
89+
)* # If there are more inline tags, match them as well.
90+
# We use "*" since there may not be any nested inline
91+
# tags.
9392
)
94-
\}/xuS',
93+
\}/Sux',
9594
$this->contents,
9695
null,
9796
PREG_SPLIT_DELIM_CAPTURE

0 commit comments

Comments
 (0)