Skip to content

Commit

Permalink
🦄 refactor: Add delete local ref call
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Mar 22, 2024
1 parent ce166bc commit aefc037
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions rust/src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,16 @@ impl JavaAstTokenFactory {
where
'local: 'a,
{
let java_string = converter::string_to_jstring(env, &text);
let text = jvalue {
l: converter::string_to_jstring(env, &text).as_raw(),
l: java_string.as_raw(),
};
let start_position = jvalue { i: range.start as i32 };
let end_position = jvalue { i: range.end as i32 };
let line_break_ahead = jvalue {
z: line_break_ahead as u8,
};
unsafe {
let token = unsafe {
env
.call_static_method_unchecked(
&self.class,
Expand All @@ -295,7 +296,9 @@ impl JavaAstTokenFactory {
.expect("Couldn't create Swc4jAstTokenIdentKnown")
.l()
.expect("Couldn't convert Swc4jAstTokenIdentKnown")
}
};
env.delete_local_ref(java_string).expect("Couldn't delete local ident");
token
}

pub fn create_keyword<'local, 'a>(
Expand Down Expand Up @@ -367,15 +370,16 @@ impl JavaAstTokenFactory {
where
'local: 'a,
{
let java_string = converter::string_to_jstring(env, &text);
let text = jvalue {
l: converter::string_to_jstring(env, &text).as_raw(),
l: java_string.as_raw(),
};
let start_position = jvalue { i: range.start as i32 };
let end_position = jvalue { i: range.end as i32 };
let line_break_ahead = jvalue {
z: line_break_ahead as u8,
};
unsafe {
let token = unsafe {
env
.call_static_method_unchecked(
&self.class,
Expand All @@ -386,7 +390,9 @@ impl JavaAstTokenFactory {
.expect("Couldn't create Swc4jAstTokenIdentOther")
.l()
.expect("Couldn't convert Swc4jAstTokenIdentOther")
}
};
env.delete_local_ref(java_string).expect("Couldn't delete local ident");
token
}

pub fn create_true<'local, 'a>(
Expand Down Expand Up @@ -427,15 +433,16 @@ impl JavaAstTokenFactory {
where
'local: 'a,
{
let java_string = converter::string_to_jstring(env, &text);
let text = jvalue {
l: converter::string_to_jstring(env, &text).as_raw(),
l: java_string.as_raw(),
};
let start_position = jvalue { i: range.start as i32 };
let end_position = jvalue { i: range.end as i32 };
let line_break_ahead = jvalue {
z: line_break_ahead as u8,
};
unsafe {
let token = unsafe {
env
.call_static_method_unchecked(
&self.class,
Expand All @@ -446,7 +453,9 @@ impl JavaAstTokenFactory {
.expect("Couldn't create Swc4jAstTokenUnknown")
.l()
.expect("Couldn't convert Swc4jAstTokenUnknown")
}
};
env.delete_local_ref(java_string).expect("Couldn't delete local text");
token
}
}

Expand Down Expand Up @@ -792,6 +801,9 @@ pub fn token_and_spans_to_java_list<'local>(
_ => java_ast_token_factory.create_unknown(env, &text, index_range, line_break_ahead),
};
java_array_list.add(env, &list, &ast_token);
env
.delete_local_ref(ast_token)
.expect("Couldn't delete local ast token");
});
list.as_raw()
}
Expand Down

0 comments on commit aefc037

Please sign in to comment.