thunderer / Shortcode

Advanced shortcode (BBCode) parser and engine for PHP

Home Page:http://kowalczyk.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unnecessary PREG_OFFSET_CAPTURE usage (?)

ViliusS opened this issue · comments

Just wondering is PREG_OFFSET_CAPTURE is needed here

$count = preg_match_all($this->lexerRegex, $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);

I don't see offset used anywhere in the following code however during tests I found that it uses up memory pretty heavily. If I did my testing right, in one case preg_match_all() uses up 80 MB with PREG_OFFSET_CAPTURE and 23 MB without.

Interesting, it looks like a leftover from the time I actually used the offset, now replaced with calculation via mb_strlen(). Would you be interested in preparing a PR for this?

I've actually tried that, but the logic in the following switch statement is a little bit over my head. What I could share is why I have investigated this, and minimal test cases which shows memory issues with that preg_match_all() statement https://1drv.ms/f/s!AgnMn-haWyFrkcN50beuEO4A0m6PQw?e=GjwcEV . Ideally I wanted to find out why these content cases uses so much memory, but other cases don't. PREG_OFFSET_CAPTURE looked like a low hanging fruit, but there could be other issues still.