libriscv / godot-sandbox

In-editor scripting and sandboxing for Godot
https://libriscv.no/docs/intro
BSD 3-Clause "New" or "Revised" License
145 stars 8 forks source link

Implement String abstraction for guests #82

Closed fwsGonzo closed 2 months ago

lyuma commented 2 months ago

I was looking at the string accessor functions to understand the ABI, and in particular the performance overhead of iterating over characters in a string

However, this strikes me as highly peculiar as it does not follow the c++ language operator conventions:

String String::operator[](int idx) const {
    unsigned new_stridx = sys_string_at(m_idx, idx);
    return String::from_variant_index(new_stridx);
}

operator[] usually returns a reference, and it usually returns a value type. This one does neither, and I am curious why. For example, it could return char32_t or int or char, depending on Unicode support