Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement Rust-side const ExternalOneByteStringResource subclass #1275

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 29 additions & 41 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,46 +122,34 @@ type OneByteConstIsCacheable = extern "C" fn(&'static OneByteConst) -> bool;
type OneByteConstData = extern "C" fn(&'static OneByteConst) -> *const char;
type OneByteConstLength = extern "C" fn(&'static OneByteConst) -> usize;

type OneByteConstVtable = (
// typeinfo / metadata pointer
*const (),
// base offset
usize,
// Destructor & Delete
OneByteConstNoOp,
OneByteConstNoOp,
// IsCacheable
OneByteConstIsCacheable,
// Dispose
OneByteConstNoOp,
// Lock
OneByteConstNoOp,
// Unlock
OneByteConstNoOp,
// Data
OneByteConstData,
// Length
OneByteConstLength,
// UpdateDataCache
OneByteConstNoOp,
// CheckCachedDataInvariants
OneByteConstNoOp,
);

const ONE_BYTE_CONST_VTABLE: OneByteConstVtable = (
std::ptr::null(),
0,
one_byte_const_no_op,
one_byte_const_no_op,
one_byte_const_is_cacheable,
one_byte_const_no_op,
one_byte_const_no_op,
one_byte_const_no_op,
one_byte_const_data,
one_byte_const_length,
one_byte_const_no_op,
one_byte_const_no_op,
);
#[repr(C)]
struct OneByteConstVtable {
_typeinfo: *const (),
_base_offset: usize,
delete1: OneByteConstNoOp,
#[cfg(not(target_family = "windows"))]
delete2: OneByteConstNoOp,
is_cacheable: OneByteConstIsCacheable,
dispose: OneByteConstNoOp,
lock: OneByteConstNoOp,
unlock: OneByteConstNoOp,
data: OneByteConstData,
length: OneByteConstLength,
}

const ONE_BYTE_CONST_VTABLE: OneByteConstVtable = OneByteConstVtable {
_typeinfo: std::ptr::null(),
_base_offset: 0,
delete1: one_byte_const_no_op,
#[cfg(not(target_family = "windows"))]
aapoalas marked this conversation as resolved.
Show resolved Hide resolved
delete2: one_byte_const_no_op,
is_cacheable: one_byte_const_is_cacheable,
dispose: one_byte_const_no_op,
lock: one_byte_const_no_op,
unlock: one_byte_const_no_op,
data: one_byte_const_data,
length: one_byte_const_length,
};

/// Compile-time function to determine if a string is ASCII. Note that UTF-8 chars
/// longer than one byte have the high-bit set and thus, are not ASCII.
Expand Down Expand Up @@ -431,7 +419,7 @@ impl String {
) -> OneByteConst {
is_ascii(buffer);
OneByteConst {
vtable: &ONE_BYTE_CONST_VTABLE.2,
vtable: &ONE_BYTE_CONST_VTABLE.delete1,
aapoalas marked this conversation as resolved.
Show resolved Hide resolved
cached_data: buffer.as_ptr() as *const char,
length: buffer.len() as i32,
}
Expand Down