This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
ld-collate simplification
- To: libc-alpha at sources dot redhat dot com
- Subject: ld-collate simplification
- From: Bruno Haible <haible at ilog dot fr>
- Date: Fri, 1 Sep 2000 13:59:04 +0200 (CEST)
This patch introduces two obstack related inline functions, to reduce some
amount of code duplication in ld-collate.c.
2000-08-31 Bruno Haible <haible@clisp.cons.org>
* locale/programs/ld-collate.c (obstack_int32_grow,
obstack_int32_grow_fast): New inline functions.
(output_weightwc, collate_output): Use them where possible.
*** glibc-20000831/locale/programs/ld-collate.c.bak Thu Aug 31 13:15:23 2000
--- glibc-20000831/locale/programs/ld-collate.c Fri Sep 1 01:45:03 2000
***************
*** 41,46 ****
--- 41,64 ----
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
+ static inline void
+ obstack_int32_grow (struct obstack *obstack, int32_t data)
+ {
+ if (sizeof (int32_t) == sizeof (int))
+ obstack_int_grow (obstack, data);
+ else
+ obstack_grow (obstack, &data, sizeof (int32_t));
+ }
+
+ static inline void
+ obstack_int32_grow_fast (struct obstack *obstack, int32_t data)
+ {
+ if (sizeof (int32_t) == sizeof (int))
+ obstack_int_grow_fast (obstack, data);
+ else
+ obstack_grow (obstack, &data, sizeof (int32_t));
+ }
+
/* Forward declaration. */
struct element_t;
***************
*** 1842,1851 ****
buf[j++] = elem->weights[cnt].w[i]->wcorder;
/* And add the buffer content. */
! if (sizeof (int) == sizeof (int32_t))
! obstack_int_grow (pool, j);
! else
! obstack_grow (pool, &j, sizeof (int32_t));
obstack_grow (pool, buf, j * sizeof (int32_t));
}
--- 1860,1866 ----
buf[j++] = elem->weights[cnt].w[i]->wcorder;
/* And add the buffer content. */
! obstack_int32_grow (pool, j);
obstack_grow (pool, buf, j * sizeof (int32_t));
}
***************
*** 1931,1947 ****
/* Since we are using the sign of an integer to mark indirection the
offsets in the arrays we are indirectly referring to must not be
zero since -0 == 0. Therefore we add a bit of dummy content. */
! if (sizeof (int) == sizeof (int32_t))
! {
! obstack_int_grow (&extrapool, 0);
! obstack_int_grow (&indirectpool, 0);
! }
! else
! {
! int32_t zero = 0;
! obstack_grow (&extrapool, &zero, sizeof (zero));
! obstack_grow (&indirectpool, &zero, sizeof (zero));
! }
/* Prepare the ruleset table. */
for (sect = collate->sections, i = 0; sect != NULL; sect = sect->next)
--- 1946,1953 ----
/* Since we are using the sign of an integer to mark indirection the
offsets in the arrays we are indirectly referring to must not be
zero since -0 == 0. Therefore we add a bit of dummy content. */
! obstack_int32_grow (&extrapool, 0);
! obstack_int32_grow (&indirectpool, 0);
/* Prepare the ruleset table. */
for (sect = collate->sections, i = 0; sect != NULL; sect = sect->next)
***************
*** 2045,2060 ****
/* More than one consecutive entry. We mark this by having
a negative index into the indirect table. */
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow_fast (&extrapool,
-(obstack_object_size (&indirectpool)
/ sizeof (int32_t)));
- else
- {
- int32_t i = -(obstack_object_size (&indirectpool)
- / sizeof (int32_t));
- obstack_grow (&extrapool, &i, sizeof (int32_t));
- }
/* Now search first the end of the series. */
do
--- 2051,2059 ----
/* More than one consecutive entry. We mark this by having
a negative index into the indirect table. */
! obstack_int32_grow_fast (&extrapool,
-(obstack_object_size (&indirectpool)
/ sizeof (int32_t)));
/* Now search first the end of the series. */
do
***************
*** 2079,2089 ****
do
{
weightidx = output_weight (&weightpool, collate, curp);
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow (&indirectpool, weightidx);
! else
! obstack_grow (&indirectpool, &weightidx,
! sizeof (int32_t));
curp = curp->mblast;
}
--- 2078,2084 ----
do
{
weightidx = output_weight (&weightpool, collate, curp);
! obstack_int32_grow (&indirectpool, weightidx);
curp = curp->mblast;
}
***************
*** 2091,2100 ****
/* Add the final weight. */
weightidx = output_weight (&weightpool, collate, curp);
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow (&indirectpool, weightidx);
! else
! obstack_grow (&indirectpool, &weightidx, sizeof (int32_t));
/* And add the end byte sequence. Without length this
time. */
--- 2086,2092 ----
/* Add the final weight. */
weightidx = output_weight (&weightpool, collate, curp);
! obstack_int32_grow (&indirectpool, weightidx);
/* And add the end byte sequence. Without length this
time. */
***************
*** 2118,2127 ****
& (__alignof__ (int32_t) - 1)) == 0);
obstack_make_room (&extrapool, added);
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow_fast (&extrapool, weightidx);
! else
! obstack_grow (&extrapool, &weightidx, sizeof (int32_t));
assert (runp->nmbs <= 256);
obstack_1grow_fast (&extrapool, runp->nmbs - 1);
--- 2110,2116 ----
& (__alignof__ (int32_t) - 1)) == 0);
obstack_make_room (&extrapool, added);
! obstack_int32_grow_fast (&extrapool, weightidx);
assert (runp->nmbs <= 256);
obstack_1grow_fast (&extrapool, runp->nmbs - 1);
***************
*** 2151,2163 ****
& ~(__alignof__ (int32_t) - 1));
obstack_make_room (&extrapool, added);
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow_fast (&extrapool, 0);
! else
! {
! int32_t zero = 0;
! obstack_grow (&extrapool, &zero, sizeof (int32_t));
! }
/* XXX What rule? We just pick the first. */
obstack_1grow_fast (&extrapool, 0);
/* Length is zero. */
--- 2140,2146 ----
& ~(__alignof__ (int32_t) - 1));
obstack_make_room (&extrapool, added);
! obstack_int32_grow_fast (&extrapool, 0);
/* XXX What rule? We just pick the first. */
obstack_1grow_fast (&extrapool, 0);
/* Length is zero. */
***************
*** 2229,2245 ****
/* Since we are using the sign of an integer to mark indirection the
offsets in the arrays we are indirectly referring to must not be
zero since -0 == 0. Therefore we add a bit of dummy content. */
! if (sizeof (int) == sizeof (int32_t))
! {
! obstack_int_grow (&extrapool, 0);
! obstack_int_grow (&indirectpool, 0);
! }
! else
! {
! int32_t zero = 0;
! obstack_grow (&extrapool, &zero, sizeof (zero));
! obstack_grow (&indirectpool, &zero, sizeof (zero));
! }
/* Now insert the `UNDEFINED' value if it is used. Since this value
will probably be used more than once it is good to store the
--- 2212,2219 ----
/* Since we are using the sign of an integer to mark indirection the
offsets in the arrays we are indirectly referring to must not be
zero since -0 == 0. Therefore we add a bit of dummy content. */
! obstack_int32_grow (&extrapool, 0);
! obstack_int32_grow (&indirectpool, 0);
/* Now insert the `UNDEFINED' value if it is used. Since this value
will probably be used more than once it is good to store the
***************
*** 2297,2317 ****
/* More than one consecutive entry. We mark this by having
a negative index into the indirect table. */
! if (sizeof (int32_t) == sizeof (int))
! {
! obstack_int_grow_fast (&extrapool,
! -(obstack_object_size (&indirectpool)
! / sizeof (int32_t)));
! obstack_int_grow_fast (&extrapool, runp->nwcs - 1);
! }
! else
! {
! int32_t i = -(obstack_object_size (&indirectpool)
! / sizeof (int32_t));
! obstack_grow (&extrapool, &i, sizeof (int32_t));
! i = runp->nwcs - 1;
! obstack_grow (&extrapool, &i, sizeof (int32_t));
! }
do
runp = runp->wcnext;
--- 2271,2280 ----
/* More than one consecutive entry. We mark this by having
a negative index into the indirect table. */
! obstack_int32_grow_fast (&extrapool,
! -(obstack_object_size (&indirectpool)
! / sizeof (int32_t)));
! obstack_int32_grow_fast (&extrapool, runp->nwcs - 1);
do
runp = runp->wcnext;
***************
*** 2327,2337 ****
curp = runp;
for (i = 1; i < runp->nwcs; ++i)
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow_fast (&extrapool, curp->wcs[i]);
! else
! obstack_grow (&extrapool, &curp->wcs[i],
! sizeof (int32_t));
/* Now find the end of the consecutive sequence and
add all the indeces in the indirect pool. */
--- 2290,2296 ----
curp = runp;
for (i = 1; i < runp->nwcs; ++i)
! obstack_int32_grow_fast (&extrapool, curp->wcs[i]);
/* Now find the end of the consecutive sequence and
add all the indeces in the indirect pool. */
***************
*** 2339,2349 ****
{
weightidx = output_weightwc (&weightpool, collate,
curp);
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow (&indirectpool, weightidx);
! else
! obstack_grow (&indirectpool, &weightidx,
! sizeof (int32_t));
curp = curp->wclast;
}
--- 2298,2304 ----
{
weightidx = output_weightwc (&weightpool, collate,
curp);
! obstack_int32_grow (&indirectpool, weightidx);
curp = curp->wclast;
}
***************
*** 2351,2370 ****
/* Add the final weight. */
weightidx = output_weightwc (&weightpool, collate, curp);
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow (&indirectpool, weightidx);
! else
! obstack_grow (&indirectpool, &weightidx,
! sizeof (int32_t));
/* And add the end byte sequence. Without length this
time. */
for (i = 1; i < curp->nwcs; ++i)
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow (&extrapool, curp->wcs[i]);
! else
! obstack_grow (&extrapool, &curp->wcs[i],
! sizeof (int32_t));
}
else
{
--- 2306,2317 ----
/* Add the final weight. */
weightidx = output_weightwc (&weightpool, collate, curp);
! obstack_int32_grow (&indirectpool, weightidx);
/* And add the end byte sequence. Without length this
time. */
for (i = 1; i < curp->nwcs; ++i)
! obstack_int32_grow (&extrapool, curp->wcs[i]);
}
else
{
***************
*** 2380,2403 ****
if (sizeof (int) == sizeof (int32_t))
obstack_make_room (&extrapool, added);
! if (sizeof (int32_t) == sizeof (int))
! {
! obstack_int_grow_fast (&extrapool, weightidx);
! obstack_int_grow_fast (&extrapool, runp->nwcs - 1);
! }
! else
! {
! int32_t l = runp->nwcs - 1;
! obstack_grow (&extrapool, &weightidx,
! sizeof (int32_t));
! obstack_grow (&extrapool, &l, sizeof (int32_t));
! }
for (i = 1; i < runp->nwcs; ++i)
! if (sizeof (int32_t) == sizeof (int))
! obstack_int_grow_fast (&extrapool, runp->wcs[i]);
! else
! obstack_grow (&extrapool, &runp->wcs[i],
! sizeof (int32_t));
}
/* Next entry. */
--- 2327,2336 ----
if (sizeof (int) == sizeof (int32_t))
obstack_make_room (&extrapool, added);
! obstack_int32_grow_fast (&extrapool, weightidx);
! obstack_int32_grow_fast (&extrapool, runp->nwcs - 1);
for (i = 1; i < runp->nwcs; ++i)
! obstack_int32_grow_fast (&extrapool, runp->wcs[i]);
}
/* Next entry. */
***************
*** 2531,2543 ****
/* Now some 32-bit values: multibyte collation sequence,
wide char string (including length), and wide char
collation sequence. */
! obstack_int_grow (&extrapool, runp->mbseqorder);
! obstack_int_grow (&extrapool, runp->nwcs);
obstack_grow (&extrapool, runp->wcs,
runp->nwcs * sizeof (uint32_t));
! obstack_int_grow (&extrapool, runp->wcseqorder);
}
}
--- 2463,2475 ----
/* Now some 32-bit values: multibyte collation sequence,
wide char string (including length), and wide char
collation sequence. */
! obstack_int32_grow (&extrapool, runp->mbseqorder);
! obstack_int32_grow (&extrapool, runp->nwcs);
obstack_grow (&extrapool, runp->wcs,
runp->nwcs * sizeof (uint32_t));
! obstack_int32_grow (&extrapool, runp->wcseqorder);
}
}