Skip to content

Commit 037764f

Browse files
committed
Cleanup
1 parent 803d908 commit 037764f

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

ext/herb/extension.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,17 @@ static VALUE rb_create_diff_operation(const herb_diff_operation_T* operation) {
434434
VALUE old_node = operation->old_node != NULL ? rb_node_from_c_struct((AST_NODE_T*) operation->old_node) : Qnil;
435435
VALUE new_node = operation->new_node != NULL ? rb_node_from_c_struct((AST_NODE_T*) operation->new_node) : Qnil;
436436

437-
VALUE args[] = {
438-
type, path_array, old_node, new_node, UINT2NUM(operation->old_index), UINT2NUM(operation->new_index)
439-
};
440-
441-
return rb_class_new_instance(6, args, cDiffOperation);
437+
return rb_funcall(
438+
cDiffOperation,
439+
rb_intern("new"),
440+
6,
441+
type,
442+
path_array,
443+
old_node,
444+
new_node,
445+
UINT2NUM(operation->old_index),
446+
UINT2NUM(operation->new_index)
447+
);
442448
}
443449

444450
static VALUE diff_convert_body(VALUE arg) {

rust/src/herb.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,13 @@ pub fn diff(old_source: &str, new_source: &str) -> Result<DiffResult, String> {
346346
let new_root = crate::ffi::herb_parse(new_c_source.as_ptr(), &parser_options, &mut new_allocator);
347347

348348
if old_root.is_null() || new_root.is_null() {
349-
if !old_root.is_null() { crate::ffi::ast_node_free(old_root as *mut AST_NODE_T, &mut old_allocator); }
350-
if !new_root.is_null() { crate::ffi::ast_node_free(new_root as *mut AST_NODE_T, &mut new_allocator); }
349+
if !old_root.is_null() {
350+
crate::ffi::ast_node_free(old_root as *mut AST_NODE_T, &mut old_allocator);
351+
}
352+
353+
if !new_root.is_null() {
354+
crate::ffi::ast_node_free(new_root as *mut AST_NODE_T, &mut new_allocator);
355+
}
351356

352357
crate::ffi::hb_allocator_destroy(&mut diff_allocator);
353358
crate::ffi::hb_allocator_destroy(&mut old_allocator);

test/diff/diff_test.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,10 @@ class DiffTest < Minitest::Spec
296296
test "DiffResult#each yields operations" do
297297
result = Herb.diff("<div>Hello</div>", "<div>World</div>")
298298

299-
operations = []
300-
result.each { |op| operations << op }
299+
count = 0
300+
result.each { count += 1 }
301301

302-
assert_equal result.operations.size, operations.size
303-
assert_equal result.operations[0], operations[0]
302+
assert_equal result.operations.size, count
304303
end
305304

306305
test "DiffResult#each returns enumerator without block" do

0 commit comments

Comments
 (0)