shortenIDs: Avoid pointless renames of IDs
With the current code, scour could do a pointless remap of an ID, where there is no benefit in it. Consider: ```xml <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <rect id="a" width="80" height="50" fill="red"/> <rect id="b" width="80" height="50" fill="blue"/> </defs> <use xlink:href="#a"/> <use xlink:href="#b"/> <use xlink:href="#b"/> </svg> ``` In this example, there is no point in swapping the IDs - even if "#b" is used more often than "#a", they have the same length. Besides a performance win on an already scour'ed image, it also mean scour will behave like a function with a fixed-point (i.e. scour eventually stops altering the image). To solve this, we no longer check whether an we find exactly the same ID. Instead, we look at the length of the new ID compared to the original. This gives us a slight complication as we can now "reserve" a "future" ID to avoid the rename. Thanks to Eduard "Ede_123" Braun for providing the test case. Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
00cf42b554
commit
d6406a3470
3 changed files with 43 additions and 5 deletions
11
unittests/shorten-ids-stable-output.svg
Normal file
11
unittests/shorten-ids-stable-output.svg
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<defs>
|
||||
<rect id="a" width="80" height="50" fill="red"/>
|
||||
<rect id="b" width="80" height="50" fill="blue"/>
|
||||
</defs>
|
||||
<use xlink:href="#a"/>
|
||||
<use xlink:href="#b"/>
|
||||
<use xlink:href="#b"/>
|
||||
</svg>
|
||||
|
||||
|
After Width: | Height: | Size: 323 B |
Loading…
Add table
Add a link
Reference in a new issue