This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] avoid initialization overhead in strcoll
- From: Leonhard Holz <leonhard dot holz at web dot de>
- To: libc-alpha at sourceware dot org
- Date: Thu, 28 May 2015 17:39:01 +0200
- Subject: [PATCH] avoid initialization overhead in strcoll
- Authentication-results: sourceware.org; auth=none
This patch removes some initialization overhead in the hot path of strcoll. It
improves the file listing benchmark by 20% on x86.
filelist#C - 2.51%
filelist#en_US.UTF-8 -20.41%
lorem_ipsum#vi_VN.UTF-8 -29.86%
lorem_ipsum#en_US.UTF-8 -17.47%
lorem_ipsum#ar_SA.UTF-8 -15.81%
lorem_ipsum#zh_CN.UTF-8 - 5.03%
lorem_ipsum#cs_CZ.UTF-8 -13.44%
lorem_ipsum#en_GB.UTF-8 -14.51%
lorem_ipsum#da_DK.UTF-8 -18.99%
lorem_ipsum#pl_PL.UTF-8 -17.07%
lorem_ipsum#fr_FR.UTF-8 -16.64%
lorem_ipsum#pt_PT.UTF-8 -16.51%
lorem_ipsum#el_GR.UTF-8 -11.78%
lorem_ipsum#ru_RU.UTF-8 -14.07%
lorem_ipsum#iw_IL.UTF-8 - 9.20%
lorem_ipsum#es_ES.UTF-8 -22.05%
lorem_ipsum#hi_IN.UTF-8 2.50%
lorem_ipsum#sv_SE.UTF-8 -18.63%
lorem_ipsum#hu_HU.UTF-8 -13.16%
lorem_ipsum#tr_TR.UTF-8 -16.54%
lorem_ipsum#is_IS.UTF-8 -17.30%
lorem_ipsum#it_IT.UTF-8 -17.82%
lorem_ipsum#sr_RS.UTF-8 -22.83%
lorem_ipsum#ja_JP.UTF-8 4.99%
* string/strcoll_l.c (STRCOLL): Removed unneeded initialization overhead.
diff --git a/string/strcoll_l.c b/string/strcoll_l.c
index 0fa005f..14bfb8b 100644
--- a/string/strcoll_l.c
+++ b/string/strcoll_l.c
@@ -62,7 +62,6 @@ typedef struct
int len; /* Length of the current sequence. */
size_t val; /* Position of the sequence relative to the
previous non-ignored sequence. */
- size_t idxnow; /* Current index in sequences. */
size_t idxmax; /* Maximum index in sequences. */
size_t idxcnt; /* Current count of indices. */
size_t backw; /* Current Backward sequence index. */
@@ -313,20 +312,22 @@ STRCOLL (const STRING_TYPE *s1, const STRING_TYPE *s2,
__locale_t l)
assert (((uintptr_t) extra) % __alignof__ (extra[0]) == 0);
assert (((uintptr_t) indirect) % __alignof__ (indirect[0]) == 0);
- int result = 0, rule = 0;
-
+ int result = 0;
coll_seq seq1, seq2;
- memset (&seq1, 0, sizeof (seq1));
- seq2 = seq1;
+ seq1.len = 0;
+ seq1.idxmax = 0;
+ seq1.rule = 0;
+ seq2.len = 0;
+ seq2.idxmax = 0;
for (int pass = 0; pass < nrules; ++pass)
{
seq1.idxcnt = 0;
+ seq2.idxcnt = 0;
seq1.idx = 0;
seq2.idx = 0;
seq1.backw_stop = ~0ul;
seq1.backw = ~0ul;
- seq2.idxcnt = 0;
seq2.backw_stop = ~0ul;
seq2.backw = ~0ul;
@@ -338,8 +339,7 @@ STRCOLL (const STRING_TYPE *s1, const STRING_TYPE *s2,
__locale_t l)
/* We assume that if a rule has defined `position' in one section
this is true for all of them. Please note that the localedef programs
makes sure that `position' is not used at the first level. */
-
- int position = rulesets[rule * nrules + pass] & sort_position;
+ int position = rulesets[seq1.rule * nrules + pass] & sort_position;
while (1)
{
@@ -372,8 +372,6 @@ STRCOLL (const STRING_TYPE *s1, const STRING_TYPE *s2,
__locale_t l)
if (result != 0)
return result;
}
-
- rule = seq1.rule;
}
return result;