[gjs: 2/12] maint: Mark functions as [[gnu::const]]




commit b20ebb459333695bff65c36474664d1c7a0c8740
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Mar 12 11:56:16 2021 -0800

    maint: Mark functions as [[gnu::const]]
    
    Some functions cppcheck will complain about if they are used in asserts,
    but in these cases it is fine, because these functions have no side
    effects. Mark them as [[gnu::const]] because they depend only on the input
    parameters and have no side effects.

 gi/object.h       | 5 ++++-
 gi/wrapperutils.h | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/gi/object.h b/gi/object.h
index d3f1ebf5..3d707971 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -414,7 +414,10 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype,
                                            const Action& action);
 
  public:
-    [[nodiscard]] GjsListLink* get_link() { return &m_instance_link; }
+    [[nodiscard]] [[gnu::const]] GjsListLink* get_link() {
+        return &m_instance_link;
+    }
+
     static void prepare_shutdown(void);
 
     /* JSClass operations */
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 0febd1bc..777fb72c 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -167,7 +167,7 @@ class GIWrapperBase : public CWrapperPointerOps<Base> {
      * Instance, it returns you the Prototype belonging to the corresponding JS
      * prototype.
      */
-    [[nodiscard]] Prototype* get_prototype() {
+    [[nodiscard]] [[gnu::const]] Prototype* get_prototype() {
         return is_prototype() ? to_prototype() : m_proto;
     }
     [[nodiscard]] const Prototype* get_prototype() const {


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