Skip to content

Conversation

@callumgran
Copy link
Member

@callumgran callumgran commented Apr 13, 2023

Started creating a string type base on the following struct:

struct string_t {
    char *data;
    size_t length;
    size_t capacity;
};

Currently working on creating fast functions for string operations.

@LytixDev
Copy link
Member

Should we go crazy and add native unicode support for our strings?

https://github.com/SerenityOS/serenity/blob/master/AK/String.h

@LytixDev
Copy link
Member

Maybe we should consider to have two string types. Might be super duper janky. Having an immutable string is very useful. Yes -- for an immutable string you could just use the good ol' char *, but it would be nice to be able to use the same string library.

struct string_t {
    char *data;
    size_t length;
};

struct string_mut_t {
    struct string_t str;
    size_t capacity;
};

@callumgran
Copy link
Member Author

I agree to both statements above

string.c Outdated
*(s->data + i) = *(data + i);
s->length++;
if (i++ == s->capacity) {
s->capacity *= 2;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bro why u change to *=2? Strings don't usually get that much bigger so it doesn't really make sense to have possibly 2x the amount of allocated memory compared to having a mear 32 bytes extra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants