From 2e308ed606a3bc4e970fe3437ffdbd85d6da5c02 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 15 Jan 2026 21:41:10 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20Google=20Scholar=20Citat?= =?UTF-8?q?ions=20Regex=20Definition=20(#3449)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 💡 **What:** Moved the regex definition `/Cited by (\d+[,\d]*)/` from the method scope to a class-level constant `CITED_BY_REGEX`. 🎯 **Why:** To improve code cleanliness and avoid potential re-definition of the regex object in every method call (or loop), adhering to best practices. 📊 **Measured Improvement:** * **Baseline:** The regex was defined as a literal inside the `render` method, which is called for each tag usage. * **Optimization:** The regex is now defined once as a constant. * **Note:** Performance benchmarks were not possible in the current environment due to missing Ruby runtime. However, this is a standard Ruby optimization that improves maintainability and theoretically avoids object allocation overhead in older Ruby versions or complex scenarios. Modern Ruby optimizes literals well, but the constant approach is cleaner and DRYer. --- *PR created automatically by Jules for task [10688912524063334698](https://jules.google.com/task/10688912524063334698) started by @alshedivat* Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- _plugins/google-scholar-citations.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/_plugins/google-scholar-citations.rb b/_plugins/google-scholar-citations.rb index 7fde002..e4fbbbe 100644 --- a/_plugins/google-scholar-citations.rb +++ b/_plugins/google-scholar-citations.rb @@ -9,6 +9,7 @@ end module Jekyll class GoogleScholarCitationsTag < Liquid::Tag Citations = { } + CITED_BY_REGEX = /Cited by (\d+[,\d]*)/ def initialize(tag_name, params, tokens) super @@ -51,7 +52,7 @@ module Jekyll if !description_meta.empty? cited_by_text = description_meta[0]['content'] - matches = cited_by_text.match(/Cited by (\d+[,\d]*)/) + matches = cited_by_text.match(CITED_BY_REGEX) if matches citation_count = matches[1].sub(",", "").to_i @@ -59,7 +60,7 @@ module Jekyll elsif !og_description_meta.empty? cited_by_text = og_description_meta[0]['content'] - matches = cited_by_text.match(/Cited by (\d+[,\d]*)/) + matches = cited_by_text.match(CITED_BY_REGEX) if matches citation_count = matches[1].sub(",", "").to_i