<commit_before>/**
 * @author <NAME> <<EMAIL>>
 */
#ifndef MPRIS_SCROBBLER_SSTRINGS_H
#define MPRIS_SCROBBLER_SSTRINGS_H

#ifdef DEBUG
#include <assert.h>
#else
#ifndef assert
#define assert(A)
#endif
#endif

#include <inttypes.h>

#ifndef grrrs_std_alloc
#include <stdlib.h>
#define grrrs_std_alloc malloc
#endif

#ifndef grrrs_std_realloc
#include <stdlib.h>
#define grrrs_std_realloc realloc
#endif

#ifndef grrrs_std_free
#include <stdlib.h>
#define grrrs_std_free free
#endif

#ifndef GRRRS_OOM
#define GRRRS_OOM
#endif

#ifndef GRRRS_ERR
#define GRRRS_ERR(...)
#endif

#define internal static
#define _VOID(A) (NULL == (A))
#define _OKP(A) (NULL != (A))
#define _GRRRS_NULL_TOP_PTR (-2 * sizeof(uint32_t))

#define _grrr_sizeof(C) (sizeof(struct grrr_string) + ((C+1) * sizeof(char)))

#define grrrs_from_string(A) (_VOID(A) ? \
    (char *)&_grrrs_new_empty(0)->data : \
    (char *)&_grrrs_new_from_cstring(A)->data)

#define grrrs_new(A) (char*)&(_grrrs_new_empty(A)->data)
#define grrrs_free(A) _grrrs_free(A)

// TODO(marius): investigate how this aligns
struct grrr_string {
    uint32_t len; /* currently used size of data[] */
    uint32_t cap; /* available size for data[] */
    char data[];
};

//typedef struct grrr_string grrrs;

internal struct grrr_string *_grrrs_ptr(char *s)
{
    return (struct grrr_string*)(s + _GRRRS_NULL_TOP_PTR);
}


internal void _grrrs_free(void *s)
{
    if (_VOID(s)) { return; }

    struct grrr_string *gs = _grrrs_ptr(s);

    if (s != (void*)&gs->data) {
        grrrs_std_free(s);
        return;
    }
    grrrs_std_free(gs);
}

internal struct grrr_string *_grrrs_new_empty(size_t cap)
{
    struct grrr_string *result = grrrs_std_alloc(_grrr_sizeof(cap));
    if (_VOID(result)) {
        GRRRS_OOM;
        return (void*)_GRRRS_NULL_TOP_PTR;
    }

    result->len = 0;
    result->cap = cap;
    for (size_t i = 0; i <= cap; i++) {
        result->data[i] = '\0';
    }

    return result;
}

internal uint32_t __strlen(const char *s)
{
    if (_VOID(s)) { return 0; }

    uint32_t result = 0;

    while (*s++ != '\0') { result++; }
<commit_msg>Removed internal function annotation from grrrs_new_empty<commit_after>/**
 * @author <NAME> <<EMAIL>>
 */
#ifndef MPRIS_SCROBBLER_SSTRINGS_H
#define MPRIS_SCROBBLER_SSTRINGS_H

#ifdef DEBUG
#include <assert.h>
#else
#ifndef assert
#define assert(A)
#endif
#endif

#include <inttypes.h>

#ifndef grrrs_std_alloc
#include <stdlib.h>
#define grrrs_std_alloc malloc
#endif

#ifndef grrrs_std_realloc
#include <stdlib.h>
#define grrrs_std_realloc realloc
#endif

#ifndef grrrs_std_free
#include <stdlib.h>
#define grrrs_std_free free
#endif

#ifndef GRRRS_OOM
#define GRRRS_OOM
#endif

#ifndef GRRRS_ERR
#define GRRRS_ERR(...)
#endif

#define internal static
#define _VOID(A) (NULL == (A))
#define _OKP(A) (NULL != (A))
#define _GRRRS_NULL_TOP_PTR (-2 * sizeof(uint32_t))

#define _grrr_sizeof(C) (sizeof(struct grrr_string) + ((C+1) * sizeof(char)))

#define grrrs_from_string(A) (_VOID(A) ? \
    (char *)&_grrrs_new_empty(0)->data : \
    (char *)&_grrrs_new_from_cstring(A)->data)

#define grrrs_new(A) (char*)&(_grrrs_new_empty(A)->data)
#define grrrs_free(A) _grrrs_free(A)

// TODO(marius): investigate how this aligns
struct grrr_string {
    uint32_t len; /* currently used size of data[] */
    uint32_t cap; /* available size for data[] */
    char data[];
};

//typedef struct grrr_string grrrs;

internal struct grrr_string *_grrrs_ptr(char *s)
{
    return (struct grrr_string*)(s + _GRRRS_NULL_TOP_PTR);
}


internal void _grrrs_free(void *s)
{
    if (_VOID(s)) { return; }

    struct grrr_string *gs = _grrrs_ptr(s);

    if (s != (void*)&gs->data) {
        grrrs_std_free(s);
        return;
    }
    grrrs_std_free(gs);
}

struct grrr_string *_grrrs_new_empty(size_t cap)
{
    struct grrr_string *result = grrrs_std_alloc(_grrr_sizeof(cap));
    if (_VOID(result)) {
        GRRRS_OOM;
        return (void*)_GRRRS_NULL_TOP_PTR;
    }

    result->len = 0;
    result->cap = cap;
    for (size_t i = 0; i <= cap; i++) {
        result->data[i] = '\0';
    }

    return result;
}

internal uint32_t __strlen(const char *s)
{
    if (_VOID(s)) { return 0; }

    uint32_t result = 0;

    while (*s++ != '\0') { result++; }

{'fraction_non_alphanumeric': 0.1459166862791245, 'fraction_numerical': 0.00894328077194634, 'mean_word_length': 4.053507728894173, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7007749', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1747, 'n_words': 376}