Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
faster node mif check
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Nov 11, 2024
1 parent 85ffadf commit aea1084
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/faebryk/core/cpp/include/graph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ using HierarchicalNodeRef = std::pair<Node_ref, std::string>;
using Link_weak_ref = Link *;

class Node {
private:
std::optional<nb::object> py_handle{};

public:
struct NodeException : public std::runtime_error {
NodeException(Node &node, const std::string &msg)
Expand All @@ -58,6 +55,7 @@ class Node {
class Type {
private:
nb::handle type;
bool hack_cache_is_moduleinterface;

public:
Type(nb::handle type);
Expand All @@ -68,6 +66,10 @@ class Node {
static nb::type_object get_moduleinterface_type();
};

private:
std::optional<nb::object> py_handle{};
std::optional<Type> type{};

private:
std::shared_ptr<GraphInterfaceSelf> self;

Expand Down
11 changes: 7 additions & 4 deletions src/faebryk/core/cpp/src/graph/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void Node::set_py_handle(nb::object handle) {
}
assert(handle.is_valid());
this->py_handle = handle;
this->type = Type(handle.type());
}

std::shared_ptr<Graph> Node::get_graph() {
Expand Down Expand Up @@ -217,14 +218,17 @@ Node::get_children(bool direct_only, std::optional<std::vector<nb::type_object>>
}

Node::Type Node::get_type() {
if (!this->py_handle) {
if (!this->type) {
throw std::runtime_error("Node has no py_handle");
}
return Type(this->py_handle.value().type());
return *this->type;
}

Node::Type::Type(nb::handle type)
: type(type) {
// TODO can be done in a nicer way
this->hack_cache_is_moduleinterface =
pyutil::issubclass(this->type, this->get_moduleinterface_type());
}

bool Node::Type::operator==(const Type &other) const {
Expand All @@ -244,8 +248,7 @@ std::string Node::Type::get_name() {
}

bool Node::Type::is_moduleinterface() {
// TODO can be done in a nicer way
return pyutil::issubclass(this->type, this->get_moduleinterface_type());
return this->hack_cache_is_moduleinterface;
}

nb::type_object Node::Type::get_moduleinterface_type() {
Expand Down

0 comments on commit aea1084

Please sign in to comment.