Files
Kevin Newton 8f4f3fdd8d [ruby/prism] Make strings just a view into memory
We do not want strings to have the ability or the contract of
having to be freed. This makes the API simpler and keeps us away
from dynamic allocation.

https://github.com/ruby/prism/commit/c9b06230ec
2026-10-20 16:00:01 -04:00

31 lines
873 B
C

#ifndef PRISM_INTERNAL_STRINGY_H
#define PRISM_INTERNAL_STRINGY_H
#include "prism/stringy.h"
/*
* Backing storage for an empty string.
*/
static const uint8_t empty_source[] = "";
/*
* Defines an empty string. This is useful for initializing a string that will
* be filled in later.
*/
#define PM_STRING_EMPTY ((pm_string_t) { .source = empty_source, .length = 0 })
/*
* Initialize a shared string that is based on initial input.
*/
void pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end);
/*
* Compare the underlying lengths and bytes of two strings. Returns 0 if the
* strings are equal, a negative number if the left string is less than the
* right string, and a positive number if the left string is greater than the
* right string.
*/
int pm_string_compare(const pm_string_t *left, const pm_string_t *right);
#endif