[gjs: 3/9] arg-cache: Remove arg position from generic argument
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 3/9] arg-cache: Remove arg position from generic argument
- Date: Mon, 10 Jan 2022 01:47:47 +0000 (UTC)
commit 2eb740dbcf0db9c5566a1b8ae380f9ee8c698ee8
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Sat Oct 16 21:52:05 2021 -0700
arg-cache: Remove arg position from generic argument
Not all the argument types care about their positioning, actually just a
few of them, so we can just apply it to the types that need it.
We can save 8 bits in most of these cases.
gi/arg-cache.cpp | 15 +++++++++++++--
gi/arg-cache.h | 9 ---------
2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index d655c564..a838643d 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -189,6 +189,16 @@ struct Nullable {
}
};
+struct Positioned {
+ void set_arg_pos(int pos) {
+ g_assert(pos <= Argument::MAX_ARGS &&
+ "No more than 253 arguments allowed");
+ m_arg_pos = pos;
+ }
+
+ uint8_t m_arg_pos = 0;
+};
+
struct Array : BasicType {
uint8_t m_length_pos = 0;
@@ -299,7 +309,7 @@ struct GenericIn : Generic {
GIArgument*) override;
};
-struct GenericInOut : GenericIn {
+struct GenericInOut : GenericIn, Positioned {
bool in(JSContext*, GjsFunctionCallState*, GIArgument*,
JS::HandleValue) override;
bool out(JSContext*, GjsFunctionCallState*, GIArgument*,
@@ -1478,7 +1488,8 @@ std::unique_ptr<T> Argument::make(uint8_t index, const char* name,
"name was ignored in RETURN_VALUE parameter");
arg->set_return_value();
} else {
- arg->set_arg_pos(index);
+ if constexpr (std::is_base_of_v<Arg::Positioned, T>)
+ arg->set_arg_pos(index);
arg->m_arg_name = name;
}
diff --git a/gi/arg-cache.h b/gi/arg-cache.h
index 15491601..1560c42a 100644
--- a/gi/arg-cache.h
+++ b/gi/arg-cache.h
@@ -15,7 +15,6 @@
#include <girepository.h>
#include <glib-object.h>
-#include <glib.h> // for g_assert
#include <js/TypeDecls.h>
@@ -99,26 +98,18 @@ struct Argument {
protected:
Argument() : m_skip_in(false), m_skip_out(false) {}
- void set_arg_pos(int pos) {
- g_assert(pos <= MAX_ARGS && "No more than 253 arguments allowed");
- m_arg_pos = pos;
- }
-
void set_instance_parameter() {
- m_arg_pos = INSTANCE_PARAM;
m_arg_name = "instance parameter";
m_skip_out = true;
}
void set_return_value() {
- m_arg_pos = RETURN_VALUE;
m_arg_name = "return value";
}
bool invalid(JSContext*, const char* func = nullptr) const;
const char* m_arg_name = nullptr;
- uint8_t m_arg_pos = 0;
bool m_skip_in : 1;
bool m_skip_out : 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]