Commit graph

7 commits

Author SHA1 Message Date
thiemowmde
69c5757243 parser: Optimize regex patterns used in LinkHolderArray
Two micro-optimizations are done in this patch:

1. We know exactly how these placeholders are built in the makeHolder()
method. In »<!--IWLINK'" 1-->« it's guaranteed to be a single number
and in »<!--LINK'" 1:2-->« it's two numbers.

The most extreme synthetic micro benchmark I did cuts the runtime of
these regular expressions down to about 25%. It won't make much of a
difference in real-world scenarios but is still worth it, I believe.

It also makes the code more specific and less confusing (see below).

2. We don't need to use the full string »<!--LINK'" 1:2-->« as array
key when the only thing that matters is the part »1:2«. Note the same
is done just a few lines below in the replaceInterwiki() method.

This code does have outstanding test coverage via all the parser tests,
I believe. Any change here that doesn't make a test fail should be safe.

Note the unit tests have been written many years later via I2c12cc7,
using "dummy" strings and such instead of the expected numeric
namespace and link ids. Most of this is already fixed via previous
patches. The last mistake addressed in this patch is that
getPrefixedDBkey() is supposed to be a title. It can't contain one of
these placeholders.

Follow-Up: I2c12cc76a9bf01eb527db3ea038e4adc59446cac
Change-Id: Ie994059092df8861ddb97c098acd082698d45c53
2023-01-07 13:25:33 +00:00
thiemowmde
800fd1d4c4 Fix bogus nextLinkID in LinkHolderArrayIntegrationTest
Parser::nextLinkID cannot return a string. It returns a positive
integer number.

Note a very similar mistake was already fixed before via I7e71ffc.

Change-Id: Ifce71d0f4db31787bf0eb84e621cfdeb07c674ef
2022-12-09 11:45:09 +01:00
Derick Alangi
5e8cd2c838
Migrate from setMwGlobals() to overrideConfigValue(s)
Change-Id: I3f167d0e7d59a5aa091c3095a7d96c889d6e7e78
2022-08-02 10:14:10 +01:00
daniel
61a5531e4a Strict return types for PageIdentity
Bug: T208776
Change-Id: I7e71ffc209465b7cca385603d844cd40178485a9
2021-01-18 17:33:14 +01:00
Tim Starling
f7f6f0d700 Update LinkHolderArray tests for new HookContainer parameter
Change-Id: I63fc731ca1dbaef6f215279ee0b1788e735783df
2020-06-23 09:00:32 +10:00
Thiemo Kreuz
231bcef6af parser: Remove unused $query param from LinkHolderArray::makeHolder
We know it's never anything but an empty array:
https://codesearch.wmflabs.org/search/?q=makeHolder

Change-Id: Ibc230ec1a1a15a9a5dc61abe5b989a3391d671c1
2020-06-22 14:33:59 +00:00
ArtBaltai
757072d182 New unit and integraton tests for class LinkHolderArray
Bug: T243747
Change-Id: I2c12cc76a9bf01eb527db3ea038e4adc59446cac
2020-06-04 11:38:40 +00:00