实现原理
Category和Class Extension的区别
Category添加的实例方法是存储在其对应的类对象里,类方法存储在其对应的元类对象里
Category添加的方法是在runtime过程中动态添加的
Category编译完成后结构
多个分类
int mcount = 0;
int i = cats->count; // cats 为分类数组
while (i--) {
auto& entry = cats->list[i];
method_list_t *mlist = entry.cat->methodsFoMeta(isMeta);
mlists[mcount++] = mlist;
// 后编译的分类方法先取出来添加到方法
// ...
}
struct _category_t {
const char *name;
struct _class_t *cls;
const struct _method_list_t *instance_methods;
const struct _method_list_t *class_methods;
const struct _protocol_list_t *protocols;
const struct _prop_list_t *properties;
};
void attachList(List* const * addedLists, uint32_t addedCount) {
if (addedCount == 0) return;
if (haveArray()) {
uint32_t oldCount = array()->count;
uint32_t newCount = oldCount + addedCount;
setArray((array_t *)realloc(array(), array_t::byteSize(newCount)));
array()->count = newCount;
memmove(array()->lists, addedLists, addedCount * sizeof(array()->lists[0]));
memcopy(array()->lists, addedLists, addedCount * sizeof(array()->lists[0]));
}
}
void attachLists(List* const * addedLists, uint32_t addedCount) {
if (addedCount == 0) return;
if (hasArray()) {
// many lists ->many lists
uint32_t oldCount = array()->count;
uint32_t newCount = oldCount + addedCount;
array_t *newArray = (array_t *)malloc(array_t::byteSize(newCount));
newArray->count = newCount;
array()->count = newCount;
for (int i = oldCount - 1; i >= 0; i--)
newArray->lists[i + addedCount] = array()->lists[i];
for (unsigned i = 0; i< addedCount; i++)
newArray->lists[i] = addedLists[i];
free(array());
setArray(newArray);
validate();
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网站栏目:Category-创新互联
本文网址:https://www.cdcxhl.com/article32/dicdpc.html
成都网站建设公司_创新互联,为您提供网站导航、网页设计公司、搜索引擎优化、网站排名、移动网站建设、定制网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联