You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/08/05 13:17:21 UTC
git commit: Use a raw Method** array in Class
Repository: lucy-clownfish
Updated Branches:
refs/heads/method_array [created] 49c8a0410
Use a raw Method** array in Class
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/49c8a041
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/49c8a041
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/49c8a041
Branch: refs/heads/method_array
Commit: 49c8a0410cf05207e1145546bda9501ef6f0a560
Parents: 71bdaae
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Tue Aug 5 13:16:23 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Tue Aug 5 13:16:23 2014 +0200
----------------------------------------------------------------------
runtime/core/Clownfish/Class.c | 29 +++++++++++++++++++----------
runtime/core/Clownfish/Class.cfh | 18 ++++++++++--------
2 files changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/49c8a041/runtime/core/Clownfish/Class.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.c b/runtime/core/Clownfish/Class.c
index 0220b3a..81c3138 100644
--- a/runtime/core/Clownfish/Class.c
+++ b/runtime/core/Clownfish/Class.c
@@ -147,17 +147,21 @@ Class_bootstrap(const ClassSpec *specs, size_t num_specs)
Class *klass = *spec->klass;
klass->name = Str_newf("%s", spec->name);
- klass->methods = VA_new(0);
+ klass->methods = (Method**)MALLOCATE((spec->num_novel_meths + 1)
+ * sizeof(Method*));
+ // Only store novel methods for now.
for (size_t i = 0; i < spec->num_novel_meths; ++i) {
const NovelMethSpec *mspec = &spec->novel_meth_specs[i];
String *name = Str_newf("%s", mspec->name);
Method *method = Method_new(name, mspec->callback_func,
*mspec->offset);
- VA_Push(klass->methods, (Obj*)method);
+ klass->methods[i] = method;
DECREF(name);
}
+ klass->methods[spec->num_novel_meths] = NULL;
+
Class_add_to_registry(klass);
}
}
@@ -232,7 +236,13 @@ Class_Get_Obj_Alloc_Size_IMP(Class *self) {
VArray*
Class_Get_Methods_IMP(Class *self) {
- return self->methods;
+ VArray *retval = VA_new(0);
+
+ for (size_t i = 0; self->methods[i]; ++i) {
+ VA_Push(retval, INCREF(self->methods[i]));
+ }
+
+ return retval;
}
void
@@ -276,6 +286,7 @@ Class_singleton(String *class_name, Class *parent) {
singleton->parent = parent;
DECREF(singleton->name);
singleton->name = Str_Clone(class_name);
+ singleton->methods = (Method**)CALLOCATE(1, sizeof(Method*));
// Allow host methods to override.
fresh_host_methods = Class_fresh_host_methods(class_name);
@@ -287,9 +298,8 @@ Class_singleton(String *class_name, Class *parent) {
Hash_Store(meths, (Obj*)meth, (Obj*)CFISH_TRUE);
}
for (Class *klass = parent; klass; klass = klass->parent) {
- uint32_t max = VA_Get_Size(klass->methods);
- for (uint32_t i = 0; i < max; i++) {
- Method *method = (Method*)VA_Fetch(klass->methods, i);
+ for (size_t i = 0; klass->methods[i]; i++) {
+ Method *method = klass->methods[i];
if (method->callback_func) {
String *name = Method_Host_Name(method);
if (Hash_Fetch(meths, (Obj*)name)) {
@@ -390,11 +400,10 @@ Class_Exclude_Host_Method_IMP(Class *self, const char *meth_name) {
static Method*
S_find_method(Class *self, const char *name) {
- size_t name_len = strlen(name);
- uint32_t size = VA_Get_Size(self->methods);
+ size_t name_len = strlen(name);
- for (uint32_t i = 0; i < size; i++) {
- Method *method = (Method*)VA_Fetch(self->methods, i);
+ for (size_t i = 0; self->methods[i]; i++) {
+ Method *method = self->methods[i];
if (Str_Equals_Utf8(method->name, name, name_len)) {
return method;
}
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/49c8a041/runtime/core/Clownfish/Class.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/Class.cfh b/runtime/core/Clownfish/Class.cfh
index 3bab408..4e5c085 100644
--- a/runtime/core/Clownfish/Class.cfh
+++ b/runtime/core/Clownfish/Class.cfh
@@ -25,14 +25,14 @@ parcel Clownfish;
class Clownfish::Class inherits Clownfish::Obj {
- Class *parent;
- String *name;
- uint32_t flags;
- int32_t parcel_id;
- size_t obj_alloc_size;
- size_t class_alloc_size;
- VArray *methods;
- cfish_method_t[1] vtable; /* flexible array */
+ Class *parent;
+ String *name;
+ uint32_t flags;
+ int32_t parcel_id;
+ size_t obj_alloc_size;
+ size_t class_alloc_size;
+ Method **methods;
+ cfish_method_t[1] vtable; /* flexible array */
inert LockFreeRegistry *registry;
inert size_t offset_of_parent;
@@ -130,6 +130,8 @@ class Clownfish::Class inherits Clownfish::Obj {
size_t
Get_Obj_Alloc_Size(Class *self);
+ /** Return novel methods of the class.
+ */
VArray*
Get_Methods(Class *self);