From: Ralph Corderoy Date: Fri, 28 Apr 2017 16:12:31 +0000 (+0100) Subject: sbr/folder_read.c: Don't malloc() once per message. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/159b2a1ede7bd581508e8704112d83efd44e0dfa?hp=159b2a1ede7bd581508e8704112d83efd44e0dfa sbr/folder_read.c: Don't malloc() once per message. Instead of struct msgs having a pointer to a malloc'd array of pointers, each to a malloc'd struct bvector, 1+N, it now has a pointer to a malloc'd array of struct bvector; one malloc for all of them. This avoids the large number of calls to malloc() and free() that's linear with the size of the folder. But there are some downsides. In order to step through an array of struct bvector, code outside of sbr/vector.c needs to know the struct's size. The simplest way to do this is to make the struct's definition public, with a comment that access should be through vector.c. New functions are needed to initialise the content of an already allocated bvector, and to finish with its content prior to deallocation. bvector_create() and bvector_free() now also use these new functions. Before, it was the array of pointers to bvector that would be realloc'd. That doesn't work for the array of bvectors as they may contain pointers to within themselves. The solution is to malloc a new array and bvector_copy() the ones to keep across, as folder_realloc() now does. The other half of its logic that coped with growth at the end of the array, has been deleted. Also deleted, is the code to clear the bvectors before and after the old ones as they start in that state. ---