Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: media/PRESUBMIT.py

Issue 1407093002: media/PRESUBMIT.py: adding CheckPassByValue for base::Time and derived classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tested Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/PRESUBMIT.py
diff --git a/media/PRESUBMIT.py b/media/PRESUBMIT.py
index feba2f719a5c6fe3c35fdb514af8fb5ef61cbbd4..8f654c481f9a51cb1b821df6155b7f6f2b9d907f 100644
--- a/media/PRESUBMIT.py
+++ b/media/PRESUBMIT.py
@@ -8,6 +8,9 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools.
"""
+import re
+import string
+
def _FilterFile(affected_file):
"""Return true if the file could contain code requiring a presubmit check."""
return affected_file.LocalPath().endswith(
@@ -158,11 +161,33 @@ def _CheckForHistogramOffByOne(input_api, output_api):
return []
+def _CheckPassByValue(input_api,
sandersd (OOO until July 31) 2015/10/16 00:54:31 No need to wrap arguments.
mcasas 2015/10/16 18:00:11 Done.
+ output_api):
+ local_errors = []
+
+ # Well-defined simple classes containing only <= 4 ints, or <= 2 floats.
+ pass_by_value_types = ['base::Time',
+ 'base::TimeTicks',
+ ]
+
+ for f in input_api.AffectedSourceFiles(_FilterFile):
+ contents = input_api.ReadFile(f, 'rb')
+ match = re.search(
+ r'\bconst +' + '(?P<type>(%s))&' %
sandersd (OOO until July 31) 2015/10/16 00:54:31 This regex should be precompiled, eg: PASS_BY_VAL
mcasas 2015/10/16 18:00:11 Done.
+ string.join(pass_by_value_types, '|'),
sandersd (OOO until July 31) 2015/10/16 00:54:31 Instead of building 'const foo&|cost bar&', it wou
mcasas 2015/10/16 18:00:11 Isn't it what's done? Regexp is r'... <type>(%s))
sandersd (OOO until July 31) 2015/10/16 18:27:12 Hmm, you're correct, but that means there is no ne
mcasas 2015/10/16 21:40:42 Done.
+ contents)
+ if match:
sandersd (OOO until July 31) 2015/10/16 00:54:31 Note that there is also .findall(), which iterates
mcasas 2015/10/16 18:00:11 My first goal was to stick as much as possible to
sandersd (OOO until July 31) 2015/10/16 18:27:12 Probably best to list them all, it's a trivial cha
mcasas 2015/10/16 21:40:42 Not that trivial since find_all() would not give t
+ local_errors.append(output_api.PresubmitError(
+ '%s passes %s by const ref instead of by value.' %
+ (f.LocalPath(), match.group('type'))))
+ return local_errors
+
def _CheckChange(input_api, output_api):
results = []
results.extend(_CheckForUseOfWrongClock(input_api, output_api))
results.extend(_CheckForMessageLoopProxy(input_api, output_api))
+ results.extend(_CheckPassByValue(input_api, output_api))
results.extend(_CheckForHistogramOffByOne(input_api, output_api))
return results
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698