1
0
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:
Aidan Woods
2019-02-10 17:49:26 +00:00
parent 41fb6b0d43
commit 36fac49ed8
8 changed files with 11 additions and 33 deletions

View File

@ -65,10 +65,7 @@ final class BlockQuote implements ContinuableBlock
return null;
}
if (
\substr($Context->line()->text(), 0, 1) === '>'
&& \preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)
) {
if (\preg_match('/^(>[ \t]?+)(.*+)/', $Context->line()->text(), $matches)) {
$indentOffset = $Context->line()->indentOffset() + $Context->line()->indent() + \strlen($matches[1]);
$recoveredSpaces = 0;

View File

@ -33,13 +33,11 @@ final class Reference implements StateUpdatingBlock
) {
$State = $State ?: new State;
if (\strpos($Context->line()->text(), ']') !== false
&& \preg_match(
'/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/',
$Context->line()->text(),
$matches
)
) {
if (\preg_match(
'/^\[(.+?)\]:[ ]*+<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*+$/',
$Context->line()->text(),
$matches
)) {
$id = \strtolower($matches[1]);
$Data = [

View File

@ -43,9 +43,7 @@ final class Email implements Inline
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@'
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*';
if (\strpos($Excerpt->text(), '>') !== false
&& \preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)
) {
if (\preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)) {
$url = $matches[1];
if (! isset($matches[2])) {

View File

@ -62,10 +62,7 @@ final class Emphasis implements Inline
return null;
}
if (
\substr($Excerpt->text(), 1, 1) === $marker
&& \preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)
) {
if (\preg_match(self::$STRONG_REGEX[$marker], $Excerpt->text(), $matches)) {
$emphasis = 'strong';
} elseif (\preg_match(self::$EM_REGEX[$marker], $Excerpt->text(), $matches)) {
$emphasis = 'em';

View File

@ -36,10 +36,6 @@ final class Markup implements Inline
*/
public static function build(Excerpt $Excerpt, State $State)
{
if (\strpos($Excerpt->text(), '>') === false) {
return null;
}
$secondChar = \substr($Excerpt->text(), 1, 1);
if ($secondChar === '/' && \preg_match('/^<\/\w[\w-]*+[ ]*+>/s', $Excerpt->text(), $matches)) {

View File

@ -41,7 +41,7 @@ final class Strikethrough implements Inline
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]));
}

View File

@ -37,15 +37,7 @@ final class Url implements Inline
*/
public static function build(Excerpt $Excerpt, State $State)
{
$text = $Excerpt->text();
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)
) {
if (\preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $Excerpt->context(), $matches, \PREG_OFFSET_CAPTURE)) {
return new self($matches[0][0], \intval($matches[0][1]));
}

View File

@ -33,7 +33,7 @@ final class UrlTag implements Inline
*/
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]));
}