Skip to content

Commit

Permalink
Prevent string copies for manual methods
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmhewitt committed Feb 9, 2023
1 parent f3646fb commit 3d5d166
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions glib/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ impl Regex {
replacement: &str,
match_options: RegexMatchFlags,
) -> Result<crate::GString, crate::Error> {
let string_len = string.len() as _;
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_regex_replace(
self.to_glib_none().0,
string.to_glib_none().0,
string_len,
string.as_ptr() as *const _,
string.len() as _,
start_position,
replacement.to_glib_none().0,
match_options.into_glib(),
Expand All @@ -39,14 +38,13 @@ impl Regex {
start_position: i32,
match_options: RegexMatchFlags,
) -> Result<MatchInfo, crate::Error> {
let string_len = string.len() as _;
unsafe {
let mut match_info = ptr::null_mut();
let mut error = ptr::null_mut();
let is_ok = ffi::g_regex_match_all_full(
self.to_glib_none().0,
string.to_glib_none().0,
string_len,
string.as_ptr() as *const _,
string.len() as _,
start_position,
match_options.into_glib(),
&mut match_info,
Expand All @@ -68,14 +66,13 @@ impl Regex {
start_position: i32,
match_options: RegexMatchFlags,
) -> Result<MatchInfo, crate::Error> {
let string_len = string.len() as _;
unsafe {
let mut match_info = ptr::null_mut();
let mut error = ptr::null_mut();
let is_ok = ffi::g_regex_match_full(
self.to_glib_none().0,
string.to_glib_none().0,
string_len,
string.as_ptr() as *const _,
string.len() as _,
start_position,
match_options.into_glib(),
&mut match_info,
Expand All @@ -98,13 +95,12 @@ impl Regex {
replacement: &str,
match_options: RegexMatchFlags,
) -> Result<crate::GString, crate::Error> {
let string_len = string.len() as _;
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_regex_replace_literal(
self.to_glib_none().0,
string.to_glib_none().0,
string_len,
string.as_ptr() as *const _,
string.len() as _,
start_position,
replacement.to_glib_none().0,
match_options.into_glib(),
Expand All @@ -126,13 +122,12 @@ impl Regex {
match_options: RegexMatchFlags,
max_tokens: i32,
) -> Result<Vec<crate::GString>, crate::Error> {
let string_len = string.len() as _;
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_regex_split_full(
self.to_glib_none().0,
string.to_glib_none().0,
string_len,
string.as_ptr() as *const _,
string.len() as _,
start_position,
match_options.into_glib(),
max_tokens,
Expand Down

0 comments on commit 3d5d166

Please sign in to comment.