Last active
July 11, 2016 01:16
-
-
Save rday/e365b7d1e932b92125c22ac31c5629f2 to your computer and use it in GitHub Desktop.
Don't sort gids that are already sorted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/sys/kern/kern_prot.c | |
+++ b/sys/kern/kern_prot.c | |
@@ -2045,12 +2045,22 @@ crsetgroups_locked(struct ucred *cr, int ngrp, gid_t *groups) | |
int i; | |
int j; | |
gid_t g; | |
+ unsigned int sorted = 0; | |
KASSERT(cr->cr_agroups >= ngrp, ("cr_ngroups is too small")); | |
bcopy(groups, cr->cr_groups, ngrp * sizeof(gid_t)); | |
cr->cr_ngroups = ngrp; | |
+ /* If the groups are already sorted, don't sort again */ | |
+ for (i = 0; i < ngrp-1; i++) { | |
+ sorted += (cr->cr_groups[i] > cr->cr_groups[i+1]); | |
+ } | |
+ | |
+ if (sorted==0) { | |
+ return; | |
+ } | |
+ | |
/* | |
* Sort all groups except cr_groups[0] to allow groupmember to | |
* perform a binary search. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment