mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Remove redundant checks
These don't appear to have a measurable positive impact on performance.
This commit is contained in:
@@ -65,10 +65,7 @@ final class BlockQuote implements ContinuableBlock
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (\preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) {
|
||||||
\substr($Context->line()->text(), 0, 1) === '>'
|
|
||||||
&& \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)
|
|
||||||
) {
|
|
||||||
$indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]);
|
$indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]);
|
||||||
|
|
||||||
$recoveredSpaces = 0;
|
$recoveredSpaces = 0;
|
||||||
|
|||||||
@@ -33,13 +33,11 @@ final class Reference implements StateUpdatingBlock
|
|||||||
) {
|
) {
|
||||||
$State = $State ?: new State;
|
$State = $State ?: new State;
|
||||||
|
|
||||||
if (\strpos($Context->line()->text(), ']') !== false
|
if (\preg_match(
|
||||||
&& \preg_match(
|
'/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/',
|
||||||
'/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/',
|
$Context->line()->text(),
|
||||||
$Context->line()->text(),
|
$matches
|
||||||
$matches
|
)) {
|
||||||
)
|
|
||||||
) {
|
|
||||||
$id = \strtolower($matches[1]);
|
$id = \strtolower($matches[1]);
|
||||||
|
|
||||||
$Data = [
|
$Data = [
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ final class Email implements Inline
|
|||||||
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
|
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
|
||||||
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
|
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
|
||||||
|
|
||||||
if (\strpos($Excerpt->text(), '>') !== false
|
if (\preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)) {
|
||||||
&& \preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)
|
|
||||||
) {
|
|
||||||
$url = $matches[1];
|
$url = $matches[1];
|
||||||
|
|
||||||
if (! isset($matches[2])) {
|
if (! isset($matches[2])) {
|
||||||
|
|||||||
@@ -62,10 +62,7 @@ final class Emphasis implements Inline
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (\preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||||
\substr($Excerpt->text(), 1, 1) === $marker
|
|
||||||
&& \preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)
|
|
||||||
) {
|
|
||||||
$emphasis = 'strong';
|
$emphasis = 'strong';
|
||||||
} elseif (\preg_match(self::$EM_REGEX[$marker], $Excerpt->text(), $matches)) {
|
} elseif (\preg_match(self::$EM_REGEX[$marker], $Excerpt->text(), $matches)) {
|
||||||
$emphasis = 'em';
|
$emphasis = 'em';
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ final class Markup implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
if (\strpos($Excerpt->text(), '>') === false) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$secondChar = \substr($Excerpt->text(), 1, 1);
|
$secondChar = \substr($Excerpt->text(), 1, 1);
|
||||||
|
|
||||||
if ($secondChar === '/' && \preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt->text(), $matches)) {
|
if ($secondChar === '/' && \preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt->text(), $matches)) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ final class Strikethrough implements Inline
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\substr($text, 1, 1) === '~' && \preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
|
if (\preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $text, $matches)) {
|
||||||
return new self($matches[1], \strlen($matches[0]));
|
return new self($matches[1], \strlen($matches[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,15 +37,7 @@ final class Url implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
$text = $Excerpt->text();
|
if (\preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt->context(), $matches, \PREG_OFFSET_CAPTURE)) {
|
||||||
|
|
||||||
if (\strlen($text) < 2 || \substr($text, 2, 1) !== '/') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\strpos($Excerpt->context(), 'http') !== false
|
|
||||||
&& \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt->context(), $matches, \PREG_OFFSET_CAPTURE)
|
|
||||||
) {
|
|
||||||
return new self($matches[0][0], \intval($matches[0][1]));
|
return new self($matches[0][0], \intval($matches[0][1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ final class UrlTag implements Inline
|
|||||||
*/
|
*/
|
||||||
public static function build(Excerpt $Excerpt, State $State)
|
public static function build(Excerpt $Excerpt, State $State)
|
||||||
{
|
{
|
||||||
if (\strpos($Excerpt->text(), '>') !== false && \preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt->text(), $matches)) {
|
if (\preg_match('/^<(\w++:\/{2}[^ >]++)>/i', $Excerpt->text(), $matches)) {
|
||||||
return new self($matches[1], \strlen($matches[0]));
|
return new self($matches[1], \strlen($matches[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user