APerson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/297117

Change subject: Improve page depth counting efficiency
......................................................................

Improve page depth counting efficiency

We don't need to listify a re.finditer result in order to count
the number of forward slashes that appear in a page title - all
we have to do is use the built-in function string.count(substr).

Change-Id: Ia457c837380f4681046bca64243b826e3ae7a302
---
M pywikibot/page.py
1 file changed, 1 insertion(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/17/297117/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index a59d379..5c5f2e0 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -235,8 +235,7 @@
         if not hasattr(self, '_depth'):
             # Check if the namespace allows subpages
             if self._namespace_obj.subpages:
-                # Count how many '/'s we have in the title
-                _depth = len(list(re.finditer('/', self.title())))
+                _depth = self.title().count('/')
             else:
                 # Does not allow subpages, which means depth is always 0
                 _depth = 0

-- 
To view, visit https://gerrit.wikimedia.org/r/297117
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia457c837380f4681046bca64243b826e3ae7a302
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: APerson <danielhg...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to