Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
chore(YouTube - InclusiveSpan): Check in advance whether debug log is…
Browse files Browse the repository at this point in the history
… enabled to prevent unnecessary toString invokes
  • Loading branch information
anddea committed Nov 6, 2024
1 parent 76ffbcb commit b5a15a7
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import java.util.List;

import app.revanced.integrations.shared.settings.BaseSettings;
import app.revanced.integrations.shared.settings.BooleanSetting;
import app.revanced.integrations.shared.utils.Logger;
import app.revanced.integrations.shared.utils.StringTrieSearch;

Expand All @@ -24,6 +26,8 @@ final class DummyFilter extends Filter { }

@SuppressWarnings("unused")
public final class InclusiveSpanPatch {
private static final BooleanSetting ENABLE_DEBUG_LOGGING = BaseSettings.ENABLE_DEBUG_LOGGING;

/**
* Simple wrapper to pass the litho parameters through the prefix search.
*/
Expand Down Expand Up @@ -121,9 +125,11 @@ private static String getSpanType(SpanType spanType, Object span) {
filterUsingCallbacks(filter, filter.callbacks);
}

Logger.printDebug(() -> "Using: "
+ searchTree.numberOfPatterns() + " conversion context filters"
+ " (" + searchTree.getEstimatedMemorySize() + " KB)");
if (ENABLE_DEBUG_LOGGING.get()) {
Logger.printDebug(() -> "Using: "
+ searchTree.numberOfPatterns() + " conversion context filters"
+ " (" + searchTree.getEstimatedMemorySize() + " KB)");
}
}

private static void filterUsingCallbacks(Filter filter, List<StringFilterGroup> groups) {
Expand Down Expand Up @@ -163,7 +169,10 @@ private static boolean returnEarly(SpannableString spannableString, Object span,

LithoFilterParameters parameter =
new LithoFilterParameters(conversionContext, spannableString, span, start, end, flags);
Logger.printDebug(() -> "Searching...\n\u200B\n" + parameter);

if (ENABLE_DEBUG_LOGGING.get()) {
Logger.printDebug(() -> "Searching...\n\u200B\n" + parameter);
}

return searchTree.matches(parameter.conversionContext, parameter);
} catch (Exception ex) {
Expand Down

0 comments on commit b5a15a7

Please sign in to comment.