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

Commit

Permalink
Replace idiom of .indexOf(...) !== -1 with .includes() across Catapult
Browse files Browse the repository at this point in the history
This is a follow-up CL to use the new best practices documented in
http://crrev.com/2764813005.

[email protected]
BUG=catapult:#3424

Review-Url: https://codereview.chromium.org/2768513002
  • Loading branch information
charliea authored and Commit bot committed Mar 21, 2017
1 parent eef0bb1 commit b3fd81a
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion dashboard/dashboard/elements/autocomplete-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@

maybeSelectLocus: function() {
var suggestions = this.suggestedItems || [];
if (suggestions.indexOf(this.locusItem) !== -1) {
if (suggestions.includes(this.locusItem)) {
this.selectItem(this.locusItem);
this.set('dropdownOpen', false);
}
Expand Down
8 changes: 2 additions & 6 deletions tracing/tracing/extras/chrome/cc/raster_task.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@
}

function isSliceDoingRasterization(slice) {
if (knownRasterTaskNames.indexOf(slice.title) !== -1)
return true;
return false;
return knownRasterTaskNames.includes(slice.title);
}

function isSliceDoingAnalysis(slice) {
if (knownAnalysisTaskNames.indexOf(slice.title) !== -1)
return true;
return false;
return knownAnalysisTaskNames.includes(slice.title);
}

return {
Expand Down
2 changes: 1 addition & 1 deletion tracing/tracing/extras/chrome/estimated_input_latency.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// https://github.com/catapult-project/catapult/issues/2784
function hasTitleAndCategory(event, title, category) {
return event.title === title && event.category &&
tr.b.getCategoryParts(event.category).indexOf(category) !== -1;
tr.b.getCategoryParts(event.category).includes(category);
}

function getNavStartTimestamps(rendererHelper) {
Expand Down
7 changes: 3 additions & 4 deletions tracing/tracing/extras/v8/ic_stats_entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
class ICStatsEntry {
constructor(obj) {
this.type_ = obj.type;
if (this.type_.indexOf('Store') !== -1) {
if (this.type_.includes('Store')) {
this.category_ = 'Store';
} else if (this.type_.indexOf('Load') !== -1) {
} else if (this.type_.includes('Load')) {
this.category_ = 'Load';
}
this.state_ = obj.state;
Expand All @@ -32,8 +32,7 @@
}
this.offset_ = obj.offset;
this.scriptName_ = obj.scriptName ? obj.scriptName : 'unknown';
this.isNative_ = obj.scriptName &&
obj.scriptName.indexOf('native') !== -1;
this.isNative_ = obj.scriptName && obj.scriptName.includes('native');
this.lineNum_ = obj.lineNum ? obj.lineNum : 'unknown';
this.filePosition_ = this.scriptName_ + ':' + this.lineNum_;
if (this.functionName_) {
Expand Down
4 changes: 2 additions & 2 deletions tracing/tracing/metrics/system_health/loading_metric.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// subclasses.
function hasCategoryAndName(event, category, title) {
return event.title === title && event.category &&
tr.b.getCategoryParts(event.category).indexOf(category) !== -1;
tr.b.getCategoryParts(event.category).includes(category);
}

/**
Expand Down Expand Up @@ -151,7 +151,7 @@
'data:text/html,chromewebdata'
];
function shouldIgnoreURL(url) {
return URL_BLACKLIST.indexOf(url) >= 0;
return URL_BLACKLIST.includes(url);
}

function collectTimeToEvent(
Expand Down
6 changes: 3 additions & 3 deletions tracing/tracing/metrics/system_health/power_metric.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@
for (var exp of model.userModel.expectations) {
var histogramName = exp.title.toLowerCase().replace(' ', '_');
var energyHist = undefined;
if (histogramName.indexOf('response') !== -1) {
if (histogramName.includes('response')) {
yield {
bounds: tr.b.Range.fromExplicitRange(exp.start, exp.end),
name: histogramName,
description: 'RAIL stage ' + histogramName,
perSecond: false
};
} else if (histogramName.indexOf('animation') !== -1 ||
histogramName.indexOf('idle') !== -1) {
} else if (histogramName.includes('animation') ||
histogramName.includes('idle')) {
yield {
bounds: tr.b.Range.fromExplicitRange(exp.start, exp.end),
name: histogramName,
Expand Down
2 changes: 1 addition & 1 deletion tracing/tracing/ui/analysis/generic_object_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
}
}
if (!objectReplaced) {
if (object.indexOf('\n') !== -1) {
if (object.includes('\n')) {
var lines = object.split('\n');
lines.forEach(function(line, i) {
var text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
var displayedProcessMemoryDumps = processMemoryDumps.map(
function(memoryDumps) {
return tr.b.filterItems(memoryDumps, function(pid, pmd) {
return pids.indexOf(pmd.process.pid) !== -1;
return pids.includes(pmd.process.pid);
});
});
viewEl.processMemoryDumps = displayedProcessMemoryDumps;
Expand Down
6 changes: 3 additions & 3 deletions tracing/tracing/ui/base/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
if (colInfo.width === undefined)
continue;

var hasExpandButton = columnsWithExpandButtons.indexOf(i) !== -1;
var hasExpandButton = columnsWithExpandButtons.includes(i);

var w = colInfo.width;
if (w) {
Expand Down Expand Up @@ -571,7 +571,7 @@
var td = Polymer.dom(rowToSize).children[i];

var delta;
if (this.columnsWithExpandButtons_.indexOf(i) !== -1) {
if (this.columnsWithExpandButtons_.includes(i)) {
td.style.paddingLeft = this.basicIndentation_ + 'px';
delta = this.basicIndentation_ + 'px';
} else {
Expand Down Expand Up @@ -735,7 +735,7 @@
if (this.doesColumnIndexSupportSelection(i))
Polymer.dom(td).classList.add('supports-selection');

if (this.columnsWithExpandButtons_.indexOf(i) !== -1) {
if (this.columnsWithExpandButtons_.includes(i)) {
if (rowInfo.userRow[this.subRowsPropertyName_] &&
rowInfo.userRow[this.subRowsPropertyName_].length > 0) {
td.style.paddingLeft = INDENT_SPACE + 'px';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// Special handling for Tracing.dataCollected because it is high
// bandwidth.
var isDataCollectedMessage = isStringPayload ?
payload.indexOf('"method": "Tracing.dataCollected"') !== -1 :
payload.includes('"method": "Tracing.dataCollected"') :
payload.method === 'Tracing.dataCollected';
if (isDataCollectedMessage) {
var listener = this.notificationListenersByMethodName_[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@
elementInfo = {};
annotationGroup.forEach(function(annotation) {
annotation.info.forEach(function(info) {
if (info.indexOf(ANNOTATION_TAG) !== -1)
if (info.includes(ANNOTATION_TAG))
elementInfo.tag = info.substring(
info.indexOf(ANNOTATION_TAG) +
ANNOTATION_TAG.length).toLowerCase();
else if (info.indexOf(ANNOTATION_ID) !== -1)
else if (info.includes(ANNOTATION_ID))
elementInfo.id = info.substring(
info.indexOf(ANNOTATION_ID) +
ANNOTATION_ID.length);
else if (info.indexOf(ANNOTATION_CLASS) !== -1)
else if (info.includes(ANNOTATION_CLASS))
elementInfo.class = info.substring(
info.indexOf(ANNOTATION_CLASS) +
ANNOTATION_CLASS.length);
Expand Down
2 changes: 1 addition & 1 deletion tracing/tracing/ui/side_panel/side_panel_container.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@

// Restore the active panel, or collapse
if (previouslyActivePanelType &&
supportedPanelTypes.indexOf(previouslyActivePanelType) !== -1) {
supportedPanelTypes.includes(previouslyActivePanelType)) {
this.activePanelType = previouslyActivePanelType;
Polymer.dom(this).setAttribute('expanded', true);
} else {
Expand Down

0 comments on commit b3fd81a

Please sign in to comment.