[gjs] function: Add GjsFunctionCallState::last_processed_index()



commit 8d50bf587073cb5e07a40672b70a8ceee7df92e5
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Oct 27 03:11:01 2020 +0100

    function: Add GjsFunctionCallState::last_processed_index()
    
    Small refactor to avoid repeating the same calculation.

 gi/function.cpp | 5 ++---
 gi/function.h   | 6 ++++++
 2 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 8f5a1e5e..cae434a8 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1017,7 +1017,7 @@ bool Function::finish_invoke(JSContext* cx, const JS::CallArgs& args,
     // state.processed_c_args.
     // If we start from -2 (the instance parameter), we need to process 2 more
     unsigned ffi_arg_pos = state->first_arg_offset() - 1;
-    unsigned ffi_arg_max = state->processed_c_args + state->first_arg_offset();
+    unsigned ffi_arg_max = state->last_processed_index();
     bool postinvoke_release_failed = false;
     for (int gi_arg_pos = -(state->first_arg_offset());
          gi_arg_pos < state->gi_argc && ffi_arg_pos < ffi_arg_max;
@@ -1052,8 +1052,7 @@ bool Function::finish_invoke(JSContext* cx, const JS::CallArgs& args,
     if (postinvoke_release_failed)
         state->failed = true;
 
-    g_assert(ffi_arg_pos ==
-             state->processed_c_args + state->first_arg_offset());
+    g_assert(ffi_arg_pos == state->last_processed_index());
 
     if (!r_value && m_js_out_argc > 0 && state->call_completed()) {
         // If we have one return value or out arg, return that item on its
diff --git a/gi/function.h b/gi/function.h
index 498b5481..40c3561b 100644
--- a/gi/function.h
+++ b/gi/function.h
@@ -7,6 +7,8 @@
 
 #include <config.h>
 
+#include <stdint.h>
+
 #include <unordered_set>
 #include <vector>
 
@@ -133,6 +135,10 @@ class GjsFunctionCallState {
 
     constexpr bool call_completed() { return !failed && !did_throw_gerror(); }
 
+    constexpr uint8_t last_processed_index() {
+        return first_arg_offset() + processed_c_args;
+    }
+
     [[nodiscard]] GjsAutoChar display_name() {
         GIBaseInfo* container = g_base_info_get_container(info);  // !owned
         if (container) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]