Skip to content

Commit

Permalink
std::mem::size_of is in the prelude so let's remove std::mem::!
Browse files Browse the repository at this point in the history
  • Loading branch information
rtldg committed Oct 27, 2024
1 parent c2f9355 commit 1a16228
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions srcwrhttp/src/http_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub extern "C" fn rust_handle_destroy_SRCWRWebsocket(streamid: u32) {
#[unsafe(no_mangle)]
pub extern "C" fn rust_handle_size_SRCWRWebsocket(_streamid: u32, size: &mut u32) -> bool {
// there's no nice way to calculate this so we'll just use a placeholder that's greater than size_of<WebsocketStream<MaybeTlsStream>>
*size = std::mem::size_of::<SRCWRWebsocket>() as u32 + 512;
*size = size_of::<SRCWRWebsocket>() as u32 + 512;
true
}

Expand Down Expand Up @@ -194,7 +194,7 @@ pub extern "C" fn rust_handle_size_SRCWRWebsocketMsg(
object: &mut SRCWRWebsocketMsg,
size: &mut u32,
) -> bool {
*size = (object.text.capacity() + std::mem::size_of::<SRCWRWebsocketMsg>()) as u32;
*size = (object.text.capacity() + size_of::<SRCWRWebsocketMsg>()) as u32;
true
}

Expand Down
4 changes: 2 additions & 2 deletions srcwrhttp/src/natives_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub extern "C" fn rust_handle_destroy_SRCWRHTTPReq(object: *mut SRCWRHTTPReq) {

#[unsafe(no_mangle)]
pub extern "C" fn rust_handle_size_SRCWRHTTPReq(object: &SRCWRHTTPReq, size: &mut u32) -> bool {
let mut s = std::mem::size_of::<SRCWRHTTPReq>();
let mut s = size_of::<SRCWRHTTPReq>();
if let Some(headers) = &object.headers {
for (key, value) in headers.iter() {
s += value.as_bytes().len() + key.as_str().len(); // not strictly accurate but none of this is anyway...
Expand Down Expand Up @@ -81,7 +81,7 @@ pub extern "C" fn rust_handle_destroy_SRCWRHTTPResp(object: *mut SRCWRHTTPResp)

#[unsafe(no_mangle)]
pub extern "C" fn rust_handle_size_SRCWRHTTPResp(object: &SRCWRHTTPResp, size: &mut u32) -> bool {
let mut s = std::mem::size_of::<SRCWRHTTPResp>();
let mut s = size_of::<SRCWRHTTPResp>();
for (key, value) in object.headers.iter() {
s += value.as_bytes().len() + key.as_str().len(); // not strictly accruate but none of this is anyway...
}
Expand Down
4 changes: 2 additions & 2 deletions srcwrjson/src/natives_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ pub extern "C" fn rust_handle_destroy_SRCWRJSON(object: *mut SRCWRJSON) {

#[unsafe(no_mangle)]
pub extern "C" fn rust_handle_size_SRCWRJSON(object: &SRCWRJSON, size: &mut u32) -> bool {
*size = std::mem::size_of::<SRCWRJSON>() as u32 + recursive_size_calc(&object.v) as u32; //stacker::grow(1 * 1024 * 1025, || recursive_size_calc(&obj.v)) as u32;
*size = size_of::<SRCWRJSON>() as u32 + recursive_size_calc(&object.v) as u32; //stacker::grow(1 * 1024 * 1025, || recursive_size_calc(&obj.v)) as u32;
true
}

fn recursive_size_calc(value: &Value) -> usize {
// PLEASE make a recursive json value that blows up the stack IT WOULD BE SO FUNNY
std::mem::size_of::<SRCWRJSON>()
size_of::<SRCWRJSON>()
+ match value {
Value::String(s) => s.capacity(),
Value::Array(v) => v.iter().fold(0, |a, x| a + recursive_size_calc(x)),
Expand Down

0 comments on commit 1a16228

Please sign in to comment.