Sfoglia il codice sorgente

kentry: Storage for fast access to nested entries with special purposes

Serj Kalichev 2 anni fa
parent
commit
f1ea4418f7
2 ha cambiato i file con 31 aggiunte e 0 eliminazioni
  1. 4 0
      klish/kentry.h
  2. 27 0
      klish/kscheme/kentry.c

+ 4 - 0
klish/kentry.h

@@ -106,6 +106,10 @@ ssize_t kentry_actions_len(const kentry_t *entry);
 kentry_actions_node_t *kentry_actions_iter(const kentry_t *entry);
 kaction_t *kentry_actions_each(kentry_actions_node_t **iter);
 
+// Fast access for nested entries with special purposes
+kentry_t *kentry_nested_by_purpose(const kentry_t *entry, kentry_purpose_e purpose);
+bool_t kentry_set_nested_by_purpose(kentry_t *entry, kentry_purpose_e purpose,
+	kentry_t *nested);
 
 C_DECL_END
 

+ 27 - 0
klish/kscheme/kentry.c

@@ -29,6 +29,8 @@ struct kentry_s {
 	bool_t filter; // Is entry filter. Filter can't have inline actions.
 	faux_list_t *entrys; // Nested ENTRYs
 	faux_list_t *actions; // Nested ACTIONs
+	// Fast links to nested entries with special purposes:
+	kentry_t* nested_by_purpose[KENTRY_PURPOSE_MAX];
 };
 
 
@@ -151,6 +153,8 @@ kentry_t *kentry_new(const char *name)
 		NULL, NULL, (void (*)(void *))kaction_free);
 	assert(entry->actions);
 
+	faux_bzero(entry->nested_by_purpose, sizeof(entry->nested_by_purpose));
+
 	return entry;
 }
 
@@ -230,3 +234,26 @@ bool_t kentry_link(kentry_t *dst, const kentry_t *src)
 
 	return BOOL_TRUE;
 }
+
+
+kentry_t *kentry_nested_by_purpose(const kentry_t *entry, kentry_purpose_e purpose)
+{
+	assert(entry);
+	if (!entry)
+		return NULL;
+
+	return entry->nested_by_purpose[purpose];
+}
+
+
+bool_t kentry_set_nested_by_purpose(kentry_t *entry, kentry_purpose_e purpose,
+	kentry_t *nested)
+{
+	assert(entry);
+	if (!entry)
+		return BOOL_FALSE;
+
+	entry->nested_by_purpose[purpose] = nested;
+
+	return BOOL_TRUE;
+}