From 87a0764d0ff7329dbb9554db6c9820d9f111675b Mon Sep 17 00:00:00 2001 From: glennsl Date: Tue, 18 Apr 2017 08:07:32 +0200 Subject: [PATCH] "memoize" shouldConvert --- src/extension/content/convert/Detect.re | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/extension/content/convert/Detect.re b/src/extension/content/convert/Detect.re index c816a6a..ed62a14 100644 --- a/src/extension/content/convert/Detect.re +++ b/src/extension/content/convert/Detect.re @@ -65,12 +65,28 @@ let isBlacklisted () => getBlacklist () |> List.mem (getSignificantUrl ()); let shouldConvert () => { - /* - Js.log @@ "isWhitelisted: " ^ (string_of_bool @@ isWhitelisted ()); - Js.log @@ "mightBeOcamlDoc: " ^ (string_of_bool @@ mightBeOcamlDoc ()); - Js.log @@ "isBlackListed: " ^ (string_of_bool @@ isBlacklisted ()); - Js.log @@ "shouldConvert: " ^ (string_of_bool (isWhitelisted () || (mightBeOcamlDoc () && not (isBlacklisted ())))); - */ - isWhitelisted () || (mightBeOcamlDoc () && not (isBlacklisted ())); + let cached: option bool = [%raw "window._rtShouldConvert"] |> Js.Undefined.to_opt; + switch cached { + | Some shouldConvert => shouldConvert + | None => + let isWhitelisted = isWhitelisted (); + let mightBeOcamlDoc = mightBeOcamlDoc (); + let isBlacklisted = isBlacklisted (); + let shouldConvert = isWhitelisted || (mightBeOcamlDoc && not isBlacklisted); + /* + Js.log @@ "isWhitelisted: " ^ (string_of_bool isWhitelisted); + Js.log @@ "mightBeOcamlDoc: " ^ (string_of_bool mightBeOcamlDoc); + Js.log @@ "isBlackListed: " ^ (string_of_bool isBlacklisted); + Js.log @@ "shouldConvert: " ^ (string_of_bool shouldConvert); + */ + if shouldConvert { + ignore [%raw "window._rtShouldConvert = 1"]; + } else { + ignore [%raw "window._rtShouldConvert = 0"]; + }; + + shouldConvert + } + };