This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Dan Cross 82b6ec3a3b More use of ptr_vector; avoid unnecessary copies.
Recast more code in terms of the ptr_vector abstraction.

The mail_menu.c code also made a lot of unnecessary copies
of strings.  For example, there was this code sequence:

    for (i = z; i < lines - 1; i++) {
            free(content[i]);
            content[i] = strdup(content[i + 1]);
    }
    free(content[i]);
    lines--;
    content = (char **)realloc(content, sizeof(char *) * lines);

Here, `content` represents an array of lines of text.
This code is removing an element from somewhere in that
array (possibly in the middle), and then shifting the
remaining elements over one position.

But observe the calls to `free` and `strdup` in the loop
body: the content is already dynamically allocated.  We
free whatever was in the selected position, and then make
*another copy* of the data in the next position to put
into the now-available slot in the array: repeat for the
remainder of the array's elements.

Instead, we could change this code to just shift things
down:

    free(content[z]);
    for (i = z; i < (lines - 1); ++i)
            content[i] = content[i + 1];
    --lines;
    ncontent = realloc(content, sizeof(char *) * lines);
    assert(ncontent == NULL);
    content = ncontent;

However, the ptr_vector abstraction provides us a function,
`ptr_vector_del` that deletes an element from the array and
returns the pointer, so we can rewrite this as simply:

    free(ptr_vector_del(&content, z));

No additional malloc()/free() required, which means less
pressure on the memory allocator and less copying of data.

Signed-off-by: Dan Cross <patchdev@fat-dragon.org>
2018-10-11 11:44:19 +10:00
deps Update LUA to 5.3.5 2018-07-31 22:07:40 +10:00
dist documentation work and a bug fix 2018-08-13 14:07:21 +10:00
docs documentation work and a bug fix 2018-08-13 14:07:21 +10:00
src More use of ptr_vector; avoid unnecessary copies. 2018-10-11 11:44:19 +10:00
utils More GNUmakefile cleanups. 2018-10-10 10:25:26 +10:00
.gitignore Start on qwknet support 2018-06-24 10:28:18 +10:00
.gitlab-ci.yml put -qq back in 2018-03-05 18:49:30 +10:00
.gitmodules Update git modules 2018-06-05 14:03:18 +10:00
file_id.diz update v0.10-alpha 2018-02-08 20:13:50 +10:00
GNUmakefile More GNUmakefile cleanups. 2018-10-10 10:25:26 +10:00
LICENSE.txt Added License & FILE_ID.DIZ 2016-04-09 18:22:55 +10:00
README.md Updated Documentation 2018-02-05 11:14:37 +10:00
setup.sh Run as user 2018-02-18 19:52:55 +10:00
STRINGS.CHANGES Start on qwknet support 2018-06-24 10:28:18 +10:00

MagickaBBS

A Bulletin Board System for UN*X like platforms.

For documentation, see http://docs.magickabbs.com/