Skip to content

Commit 3896054

Browse files
authored
Opimize del_history task (#433)
* Opimize del history * Update CHANGELOG, version, and added comments
1 parent 700a22d commit 3896054

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v1.8.3-alpha0
22

33
* Added the `America/Coyhaique` time zone, pr #432.
4+
* Optimize `del_history` task _(use single loop)_, pr #433.
45

56
# v1.8.2
67

inc/ti/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* "-rc0"
2626
* ""
2727
*/
28-
#define TI_VERSION_PRE_RELEASE "-alpha0"
28+
#define TI_VERSION_PRE_RELEASE "-alpha1"
2929

3030
#define TI_MAINTAINER \
3131
"Jeroen van der Heijden <jeroen@cesbit.com>"

src/ti/commits.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ vec_t * ti_commits_del(vec_t ** commits, ti_commits_options_t * options)
463463
if (!vec)
464464
return NULL;
465465

466+
/* must push from high to low as the `del_history` depends on this order */
466467
commits__init(*commits, options, &begin, &end);
467468
while (begin < end)
468469
{

src/ti/ttask.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ static int ttask__del_history(mp_unp_t * up)
750750
{
751751
vec_t ** commits;
752752
mp_obj_t obj, mp_scope, mp_id;
753-
size_t i;
754753

755754
if (mp_next(up, &obj) != MP_ARR || obj.via.sz != 2 ||
756755
mp_next(up, &mp_scope) != MP_U64 ||
@@ -779,21 +778,30 @@ static int ttask__del_history(mp_unp_t * up)
779778
commits = &ti.commits;
780779
}
781780

782-
for (i = obj.via.sz; i--;)
781+
if (obj.via.sz)
783782
{
784-
uint32_t j = 0;
783+
uint32_t i = obj.via.sz, j = (*commits)->n-1;
784+
785785
if (mp_next(up, &mp_id) != MP_U64)
786786
{
787787
log_critical("task `del_history`: invalid task data");
788788
return -1;
789789
}
790-
791-
for (vec_each(*commits, ti_commit_t, commit), j++)
790+
/* we can use a single loop as we're sure the commits in the list are
791+
* ordered from high to low */
792+
for (vec_each_rev(*commits, ti_commit_t, commit) j--)
792793
{
793794
if (commit->id == mp_id.via.u64)
794795
{
795796
ti_commit_destroy(vec_remove(*commits, j));
796-
break;
797+
if (!(--i))
798+
break;
799+
800+
if (mp_next(up, &mp_id) != MP_U64)
801+
{
802+
log_critical("task `del_history`: invalid task data");
803+
return -1;
804+
}
797805
}
798806
}
799807
}

0 commit comments

Comments
 (0)