After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 773561 - Suggested code cleanups
Suggested code cleanups
Status: RESOLVED FIXED
Product: gnome-todo
Classification: Other
Component: General
unspecified
Other Linux
: Normal minor
: ---
Assigned To: GNOME To Do maintainer(s)
GNOME To Do maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2016-10-26 23:18 UTC by Daniel Boles
Modified: 2016-10-27 00:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
task-list-view: don't keep iterating unnecessarily (1.13 KB, patch)
2016-10-26 23:20 UTC, Daniel Boles
committed Details | Review
task-list: remove unneeded parentheses in return (744 bytes, patch)
2016-10-26 23:20 UTC, Daniel Boles
committed Details | Review
task-list-view: some code cleanups (2.03 KB, patch)
2016-10-26 23:23 UTC, Daniel Boles
none Details | Review
task-list-view: apply a tiny cleanup/optimisation (1.07 KB, patch)
2016-10-26 23:47 UTC, Daniel Boles
committed Details | Review

Description Daniel Boles 2016-10-26 23:18:20 UTC
.
Comment 1 Daniel Boles 2016-10-26 23:20:00 UTC
Created attachment 338550 [details] [review]
task-list-view: don't keep iterating unnecessarily

    When removing a task, we would iterate the entire list of rows, even
    continuing after we found the task and removed it. A task should not
    occur more than once in a list, so we can exit early once it's found.

Of course, due to https://bugzilla.gnome.org/show_bug.cgi?id=773554 it seems that the same task CAN appear in the list of row children more than once... but in an ideal world, that would not be possible!

So this would save time not scanning the rest of the list when there would be no purpose.
Comment 2 Daniel Boles 2016-10-26 23:20:27 UTC
Created attachment 338551 [details] [review]
task-list: remove unneeded parentheses in return

    They do nothing, and we do not seem to have a convention of using them.
Comment 3 Daniel Boles 2016-10-26 23:23:16 UTC
Created attachment 338552 [details] [review]
task-list-view: some code cleanups

    * remove_task(): merge the two ifs, don't redundantly call row_get_task
    * set_list   (): use if (find) instead of continue, to mirror above loop

I tried to restrain myself from attacking all the continue statements everywhere. :D

For these, I think they are tidier and more intuitive, but YMMV of course.
Comment 4 Georges Basile Stavracas Neto 2016-10-26 23:35:37 UTC
Review of attachment 338550 [details] [review]:

LGTM.
Comment 5 Georges Basile Stavracas Neto 2016-10-26 23:35:59 UTC
Review of attachment 338551 [details] [review]:

LGTM
Comment 6 Daniel Boles 2016-10-26 23:37:14 UTC
(In reply to djb from comment #3)
> Created attachment 338552 [details] [review] [review]
> task-list-view: some code cleanups
> 
>     * remove_task(): merge the two ifs, don't redundantly call row_get_task
>     * set_list   (): use if (find) instead of continue, to mirror above loop
> 
> I tried to restrain myself from attacking all the continue statements
> everywhere. :D
> 
> For these, I think they are tidier and more intuitive, but YMMV of course.

buh, i forgot to invert the condition on the 2nd if... coming right up.
Comment 7 Georges Basile Stavracas Neto 2016-10-26 23:40:15 UTC
Review of attachment 338552 [details] [review]:

Needs work.

::: src/gtd-task-list-view.c
@@ +1613,3 @@
+                            G_CALLBACK (task_completed_cb),
+                            view);
+        }

I prefer to keep it the previous way, because it'd avoid getting too deep into nested calls. Using early breaks keeps the indentation low, and improves code readability.
Comment 8 Daniel Boles 2016-10-26 23:47:54 UTC
Created attachment 338553 [details] [review]
task-list-view: apply a tiny cleanup/optimisation

    We have just verified that task == gtd_task_row_get_task (l->data), so
    we can use the former for shorter code and avoidance of a function call.

After reverting that patch to use continue; this is all that's left :P

Glad the others looked OK.
Comment 9 Georges Basile Stavracas Neto 2016-10-27 00:11:23 UTC
Review of attachment 338553 [details] [review]:

LGTM.
Comment 10 Georges Basile Stavracas Neto 2016-10-27 00:16:35 UTC
Thanks for all the patches! Code cleanups are always welcomed.

Attachment 338550 [details] pushed as 4aa0e24 - task-list-view: don't keep iterating unnecessarily
Attachment 338551 [details] pushed as 04f06e8 - task-list: remove unneeded parentheses in return
Attachment 338553 [details] pushed as 482822b - task-list-view: apply a tiny cleanup/optimisation