mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor: use ffi Arena for resource management
This commit is contained in:
parent
d0bb7aaa0f
commit
747996b40c
17 changed files with 629 additions and 582 deletions
|
@ -42,16 +42,17 @@ Pointer<git_oid> fromSHA(String hex) {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
String toSHA(Pointer<git_oid> id) {
|
||||
final out = calloc.allocate<Int8>(40);
|
||||
final error = libgit2.git_oid_fmt(out, id);
|
||||
final result = out.cast<Utf8>().toDartString(length: 40);
|
||||
malloc.free(out);
|
||||
return using((Arena arena) {
|
||||
final out = arena<Int8>(40);
|
||||
final error = libgit2.git_oid_fmt(out, id);
|
||||
final result = out.cast<Utf8>().toDartString(length: 40);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Compare two oid structures.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue