[m-rev.] for review: Reduce memory allocation in string.to_upper, string.to_lower.
Zoltan Somogyi
zoltan.somogyi at runbox.com
Mon Jun 20 18:14:54 AEST 2016
On Mon, 20 Jun 2016 14:13:13 +1000, Peter Wang <novalazy at gmail.com> wrote:
> +:- pragma foreign_proc("C",
> + to_upper(StrIn::in, StrOut::uo),
> + [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
> + does_not_affect_liveness, no_sharing],
> +"
> + MR_Integer i;
> +
> + MR_make_aligned_string_copy_msg(StrOut, StrIn, MR_ALLOC_ID);
> +
> + for (i = 0; StrOut[i] != '\\0'; i++) {
> + if (StrOut[i] >= 'a' && StrOut[i] <= 'z') {
> + StrOut[i] = StrOut[i] - 'a' + 'A';
> + }
> + }
> +").
The test here (and in to_lower) will do the wrong thing on machines that use EBCDIC.
While C# and Java won't use it, C might.
Zoltan.
More information about the reviews
mailing list