Sha256: a4c51aac20001ac35eefdbc86cfa84c7673409ee77f089d4b65d12d36085f13b
Contents?: true
Size: 1.11 KB
Versions: 7
Compression:
Stored size: 1.11 KB
Contents
use libc::c_char; use std::ffi::{CStr,CString}; use std::str; pub struct RubyString; // Coercing strs into Strings has some loss of performance // You may use these methods temporarily but it would be much better // to write all of this code out in each method using just str. // // Using these methods you will still get you 10X (= 900%) performance // gain regardless. But really consider not using String. If you do // as I've intstructed the performance gains will go from 900% to 1250%. impl RubyString { #[allow(dead_code)] // FOR QUICK IMPLEMENTATION. NOT FOR PRODUCTION. // SEE BENCHMARKS FOR SANCTIONED IMPLEMENTATION. fn from_ruby(s: *const c_char) -> String { let c_str = unsafe { assert!(!s.is_null()); CStr::from_ptr(s) }; (*str::from_utf8(c_str.to_bytes()).unwrap_or("")).to_string() } #[allow(dead_code)] // FOR QUICK IMPLEMENTATION. NOT FOR PRODUCTION. // SEE BENCHMARKS FOR SANCTIONED IMPLEMENTATION. fn to_ruby<S: Into<String>>(s: S) -> *const c_char { let r_str = s.into(); let s_slice: &str = &r_str[..]; CString::new(s_slice).unwrap().into_raw() } }
Version data entries
7 entries across 7 versions & 1 rubygems