[gnome-shell] workspaceThumbnails: Replace loops with Array.find()
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] workspaceThumbnails: Replace loops with Array.find()
- Date: Wed, 11 Sep 2019 21:14:26 +0000 (UTC)
commit dfdb139d9c947d9c9b55401e625dfd7a7b518dd4
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Aug 3 16:39:40 2019 +0000
workspaceThumbnails: Replace loops with Array.find()
This is much more idiomatic and concise than iterating over
thumbnails until we find the one we are looking for.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/710
js/ui/workspaceThumbnail.js | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
---
diff --git a/js/ui/workspaceThumbnail.js b/js/ui/workspaceThumbnail.js
index c516934c96..fd60c31d2c 100644
--- a/js/ui/workspaceThumbnail.js
+++ b/js/ui/workspaceThumbnail.js
@@ -711,14 +711,12 @@ var ThumbnailsBox = GObject.registerClass({
_activateThumbnailAtPoint(stageX, stageY, time) {
let [r_, x_, y] = this.transform_stage_point(stageX, stageY);
- for (let i = 0; i < this._thumbnails.length; i++) {
- let thumbnail = this._thumbnails[i];
- let [, h] = thumbnail.get_transformed_size();
- if (y >= thumbnail.y && y <= thumbnail.y + h) {
- thumbnail.activate(time);
- break;
- }
- }
+ let thumbnail = this._thumbnails.find(t => {
+ let [, h] = t.get_transformed_size();
+ return y >= t.y && y <= t.y + h;
+ });
+ if (thumbnail)
+ thumbnail.activate(time);
}
_onButtonRelease(actor, event) {
@@ -1340,15 +1338,9 @@ var ThumbnailsBox = GObject.registerClass({
}
_activeWorkspaceChanged(_wm, _from, _to, _direction) {
- let thumbnail;
let workspaceManager = global.workspace_manager;
let activeWorkspace = workspaceManager.get_active_workspace();
- for (let i = 0; i < this._thumbnails.length; i++) {
- if (this._thumbnails[i].metaWorkspace == activeWorkspace) {
- thumbnail = this._thumbnails[i];
- break;
- }
- }
+ let thumbnail = this._thumbnails.find(t => t.metaWorkspace == activeWorkspace);
this._animatingIndicator = true;
let indicatorThemeNode = this._indicator.get_theme_node();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]