Mercurial > vim
comparison src/fileio.c @ 2244:caca0ddd789b vim73
Made crypt/decrypt faster.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 01 Jun 2010 23:37:39 +0200 |
parents | 03a5f2897db3 |
children | 772bfca06c18 |
comparison
equal
deleted
inserted
replaced
2243:03a5f2897db3 | 2244:caca0ddd789b |
---|---|
1424 &filesize, newfile, &did_ask_for_key); | 1424 &filesize, newfile, &did_ask_for_key); |
1425 /* | 1425 /* |
1426 * Decrypt the read bytes. | 1426 * Decrypt the read bytes. |
1427 */ | 1427 */ |
1428 if (cryptkey != NULL && size > 0) | 1428 if (cryptkey != NULL && size > 0) |
1429 for (p = ptr; p < ptr + size; ++p) | 1429 crypt_decode(ptr, size); |
1430 ZDECODE(*p); | |
1431 #endif | 1430 #endif |
1432 } | 1431 } |
1433 skip_read = FALSE; | 1432 skip_read = FALSE; |
1434 | 1433 |
1435 #ifdef FEAT_MBYTE | 1434 #ifdef FEAT_MBYTE |
3002 size_t len; | 3001 size_t len; |
3003 FILE *fp; | 3002 FILE *fp; |
3004 { | 3003 { |
3005 char_u *copy; | 3004 char_u *copy; |
3006 char_u small_buf[100]; | 3005 char_u small_buf[100]; |
3007 int ztemp, t; | |
3008 size_t i; | 3006 size_t i; |
3009 | 3007 |
3010 if (*buf->b_p_key == NUL) | 3008 if (*buf->b_p_key == NUL) |
3011 return fwrite(ptr, len, (size_t)1, fp); | 3009 return fwrite(ptr, len, (size_t)1, fp); |
3012 if (len < 100) | 3010 if (len < 100) |
3015 { | 3013 { |
3016 copy = lalloc(len, FALSE); | 3014 copy = lalloc(len, FALSE); |
3017 if (copy == NULL) | 3015 if (copy == NULL) |
3018 return 0; | 3016 return 0; |
3019 } | 3017 } |
3020 for (i = 0; i < len; ++i) | 3018 crypt_encode(ptr, len, copy); |
3021 { | |
3022 ztemp = ptr[i]; | |
3023 copy[i] = ZENCODE(ztemp, t); | |
3024 } | |
3025 i = fwrite(copy, len, (size_t)1, fp); | 3019 i = fwrite(copy, len, (size_t)1, fp); |
3026 if (copy != small_buf) | 3020 if (copy != small_buf) |
3027 vim_free(copy); | 3021 vim_free(copy); |
3028 return i; | 3022 return i; |
3029 } | 3023 } |
3037 buf_T *buf; | 3031 buf_T *buf; |
3038 FILE *fd; | 3032 FILE *fd; |
3039 int len; | 3033 int len; |
3040 { | 3034 { |
3041 char_u *ptr; | 3035 char_u *ptr; |
3042 char_u *p; | |
3043 | 3036 |
3044 ptr = read_string(fd, len); | 3037 ptr = read_string(fd, len); |
3045 if (ptr != NULL || *buf->b_p_key != NUL) | 3038 if (ptr != NULL || *buf->b_p_key != NUL) |
3046 for (p = ptr; p < ptr + len; ++p) | 3039 crypt_decode(ptr, len); |
3047 ZDECODE(*p); | |
3048 return ptr; | 3040 return ptr; |
3049 } | 3041 } |
3050 | 3042 |
3051 #endif /* FEAT_CRYPT */ | 3043 #endif /* FEAT_CRYPT */ |
3052 | 3044 |
5676 } | 5668 } |
5677 #endif /* FEAT_MBYTE */ | 5669 #endif /* FEAT_MBYTE */ |
5678 | 5670 |
5679 #ifdef FEAT_CRYPT | 5671 #ifdef FEAT_CRYPT |
5680 if (flags & FIO_ENCRYPTED) /* encrypt the data */ | 5672 if (flags & FIO_ENCRYPTED) /* encrypt the data */ |
5681 { | 5673 crypt_encode(buf, len, buf); |
5682 int ztemp, t, i; | |
5683 | |
5684 for (i = 0; i < len; i++) | |
5685 { | |
5686 ztemp = buf[i]; | |
5687 buf[i] = ZENCODE(ztemp, t); | |
5688 } | |
5689 } | |
5690 #endif | 5674 #endif |
5691 | 5675 |
5692 /* Repeat the write(), it may be interrupted by a signal. */ | 5676 /* Repeat the write(), it may be interrupted by a signal. */ |
5693 while (len > 0) | 5677 while (len > 0) |
5694 { | 5678 { |