In large file brute forcing the search of a specific token can be quite difficult. Detecting duplicated token can be made in a more performance way.
This commit is contained in:
InusualZ
2020-12-09 17:26:41 +00:00
parent 237fd96f9e
commit d676755f55

View File

@@ -77,28 +77,19 @@
public IndirectReferenceToken WriteToken(IToken token, int? reservedNumber = null)
{
// if you can't consider deduplicating the token.
// It must be because it's referenced by his child element, so you must have reserved a number before hand
// Example /Pages Obj
var canBeDuplicated = !reservedNumber.HasValue;
if (!canBeDuplicated)
{
if (!reservedNumbers.Remove(reservedNumber.Value))
{
throw new InvalidOperationException("You can't reuse a reserved number");
}
// When we end up writing this token, all of his child would already have been added and checked for duplicate
return AddToken(token, reservedNumber.Value);
}
var reference = FindToken(token);
if (reference == null)
if (!reservedNumber.HasValue)
{
return AddToken(token, CurrentNumber++);
}
return reference;
if (!reservedNumbers.Remove(reservedNumber.Value))
{
throw new InvalidOperationException("You can't reuse a reserved number");
}
// When we end up writing this token, all of his child would already have been added and checked for duplicate
return AddToken(token, reservedNumber.Value);
}
public int ReserveNumber()