Skip to content

Commit 2b6a2f1

Browse files
committed
Removed the now superfluous TODOs
1 parent eeed7bd commit 2b6a2f1

File tree

2 files changed

+2
-30
lines changed

2 files changed

+2
-30
lines changed

mp_fread.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,12 @@
55

66
#ifndef MP_NO_FILE
77

8-
/* TODO: It would be some effort involved to connect mp_fwrite (mp_fread) to s_faster_read_radix.
9-
10-
It is rather simple, on the other side, to just read the whole string into
11-
memory and send it to s_faster_read_radix but it would need heap that may or
12-
may not be available. So: check if there is something in the middle (e.g.: read
13-
in chunks (LSD to MSD) and send those strings to s_faster_read_radix).
14-
15-
NOTE: reading from a stream is quite fast already, especially bases of the form 2^n. */
16-
178
/* read a bigint from a file stream in ASCII */
189
mp_err mp_fread(mp_int *a, int radix, FILE *stream)
1910
{
2011
mp_err err = MP_OKAY;
2112
mp_sign sign = MP_ZPOS;
2213
int ch;
23-
mp_digit binary_radix = 0u;
2414

2515
/* make sure the radix is ok */
2616
if ((radix < 2) || (radix > 64)) {
@@ -42,10 +32,6 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream)
4232
/* clear a */
4333
mp_zero(a);
4434

45-
if (MP_IS_2EXPT((unsigned int)radix)) {
46-
binary_radix = (mp_digit)s_mp_log2_radix[radix];
47-
}
48-
4935
do {
5036
uint8_t y;
5137
unsigned pos;
@@ -62,12 +48,8 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream)
6248
}
6349

6450
/* shift up and add */
65-
if (binary_radix != 0u) {
66-
if ((err = mp_mul_2d(a, (int)binary_radix, a)) != MP_OKAY) goto LBL_ERR;
67-
} else {
68-
if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) goto LBL_ERR;
69-
}
70-
if ((err = mp_add_d(a, y, a)) != MP_OKAY) goto LBL_ERR;
51+
if ((err = mp_mul_d(a, (mp_digit)radix, a)) != MP_OKAY) goto LBL_ERR;
52+
if ((err = mp_add_d(a, y, a)) != MP_OKAY) goto LBL_ERR;
7153

7254
} while ((ch = fgetc(stream)) != EOF);
7355

s_mp_faster_to_radix.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ static int s_mp_compute_s(int t, int k)
2323
return (r > (MP_MAX_DIGIT_COUNT * MP_DIGIT_BIT)) ? 0 : (int)r;
2424
}
2525

26-
27-
/* TODO: Make variable names a bit more "talkative" */
2826
static mp_err s_mp_to_radix_recursive(const mp_int *a, char **str, size_t *part_maxlen, size_t *part_written,
2927
int radix, int32_t k, int32_t t, bool pad, bool first, mp_int *P, mp_int *R)
3028
{
@@ -52,8 +50,6 @@ static mp_err s_mp_to_radix_recursive(const mp_int *a, char **str, size_t *part_
5250
5351
See also: Modern Computer Arithmetic, version 0.5.9, page 59
5452
*/
55-
56-
/* TODO: Most of it is already in mp_reduce. Change mp_reduce to return the quotient, too? */
5753
Beta = (int)s_mp_compute_s(t+1, k);
5854
if (Beta == 0) {
5955
err = MP_OVF;
@@ -173,11 +169,6 @@ mp_err s_mp_faster_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *w
173169

174170
/* Compute initial reciprocal R[0] and expand it (R[0]^(2^k) */
175171
if ((err = mp_init_i32(&P[0], n)) != MP_OKAY) goto LTM_ERR;
176-
/* TODO: chunksize does not seem to matter much above the initial b^y, d.n.f.t. remove this line if
177-
MP_RADIX_BARRETT_START_MULTIPLICATOR is removed but don't forget the possibility that
178-
the OS does not like too many recursions. This routine does use a lot of stack
179-
and it calls other D&C algorithms (fast multiplication, fast division) that need a little
180-
slice of the stack, too (vid.: ulimit -s) */
181172
if ((err = mp_expt_n(&P[0], MP_RADIX_BARRETT_START_MULTIPLICATOR, &P[0])) != MP_OKAY) goto LTM_ERR;
182173
if ((err = mp_init(&R[0])) != MP_OKAY) goto LTM_ERR;
183174
if ((err = mp_2expt(&R[0], 2*k)) != MP_OKAY) goto LTM_ERR;
@@ -231,7 +222,6 @@ mp_err s_mp_faster_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *w
231222
if (MP_IS_POWER_OF_TWO(&P[t])) {
232223
if ((err = mp_div_2d(&R[t], mp_count_bits(&P[t]) - 1, &R[t], NULL)) != MP_OKAY) goto LTM_ERR;
233224
} else {
234-
/* TODO: does not work for all bases, check which one and also if it is worth the hassle */
235225
if ((radix == 10) && ((2 * mp_count_bits(&P[t])) > ilog2a)) {
236226
break;
237227
}

0 commit comments

Comments
 (0)