From 95c0d00944f64ab78e767f08cd1c0cc2c56b1e92 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Mon, 27 Feb 2012 18:26:22 +0100 Subject: [PATCH] get rid of some function calls when selection interfaces --- configure.ac | 2 +- include/class.h | 20 ++++++++--------- src/Makefile.am | 6 ++---- src/class.c | 50 ------------------------------------------- src/interface/class.c | 2 +- 5 files changed, 13 insertions(+), 67 deletions(-) delete mode 100644 src/class.c diff --git a/configure.ac b/configure.ac index 4545847..0ac0b25 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ AC_INIT([cclass], [0.0.1], [Georg Hopp ]) AM_INIT_AUTOMAKE AC_COPYRIGHT([Copyright (C) 2012 Georg Hopp]) AC_REVISION([$Revision: 0.01 $]) -AC_CONFIG_SRCDIR([src/class.c]) +AC_CONFIG_SRCDIR([src/testserver.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/include/class.h b/include/class.h index 759bb7a..efecb79 100644 --- a/include/class.h +++ b/include/class.h @@ -64,19 +64,23 @@ INIT_IMPL(__VA_ARGS__) \ }; struct class * const _##name = &c_##name +#define GET_CLASS(object) (*(class_ptr *)((object) - sizeof(void*))) +#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) +#define IFACE_EXISTS(class,iface) (NULL != IFACE_GET((class),(iface))) + /** * \todo actually i use gcc feature ## for variadoc... think about * a way to make this standard. */ #define _CALL(object,_iface,method,...) \ do { \ - class_ptr class = class_getClass((object)); \ + class_ptr class = GET_CLASS((object)); \ if (class->init) class->init(); \ - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \ class = class->parent; \ if (class->init) class->init(); \ - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ }; \ assert(NULL != iface->method); \ } while(0) @@ -98,20 +102,17 @@ #define PARENTCALL(object,_iface,method,...) \ do { \ struct i_##_iface * iface; \ - class_ptr class = class_getClass((object)); \ + class_ptr class = GET_CLASS((object)); \ if (class->init) class->init(); \ assert(HAS_PARENT(class)); \ class = class->parent; \ if (class->init) class->init(); \ - iface = (struct i_##_iface *)class_getInterface(&class, &i_##_iface); \ + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ assert(NULL != iface->method); \ iface->method(object, ##__VA_ARGS__); \ } while(0) -#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) -#define IFACE_EXISTS(class,iface) (NULL != IFACE_GET((class),(iface))) - #define HAS_PARENT(class) (NULL != ((class)->parent)) typedef void (* fptr_classInit)(void); @@ -126,9 +127,6 @@ struct class { struct iface_impl impl; }; -extern void * class_getInterface(class_ptr *, iface_ptr); -extern class_ptr class_getClass(void *); - #endif // __CLASS_H__ // vim: set ts=4 sw=4: diff --git a/src/Makefile.am b/src/Makefile.am index fc82844..4fbfc6a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,9 +3,7 @@ AUTOMAKE_OPTIONS = subdir-objects IFACE = interface/class.c interface/stream_reader.c interface/logger.c \ interface/stream_writer.c interface/http_intro.c \ - interface/subject.c interface/observer.c -CLASS = class.c interface.c -RB = ringbuffer.c ringbuffer/rb_read.c + interface/subject.c interface/observer.c interface.c SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c SERVER = server.c server/run.c server/close_conn.c server/poll.c \ server/handle_accept.c server/read.c @@ -41,7 +39,7 @@ AM_CFLAGS = -Wall -I ../include/ bin_PROGRAMS = testserver testserver_SOURCES = testserver.c \ - $(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ + $(IFACE) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \ $(UTILS) testserver_CFLAGS = -Wall -I ../include/ diff --git a/src/class.c b/src/class.c deleted file mode 100644 index 44a8d9f..0000000 --- a/src/class.c +++ /dev/null @@ -1,50 +0,0 @@ -/** - * \file - * Helper functions for class. - * - * \todo rename function to fit in the otherwise used scheme. - * \author Georg Hopp - * - * \copyright - * Copyright (C) 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include "class.h" -#include "interface.h" - -void * -class_getInterface(class_ptr * class, iface_ptr _iface) -{ - void * iface = (void *)IFACE_GET(*class, _iface); - - while(NULL == iface && HAS_PARENT(*class)) { - *class = (*class)->parent; - iface = (void *)IFACE_GET(*class, _iface); - } - - return iface; -} - -class_ptr -class_getClass(void * object) -{ - return *(class_ptr *)(object - sizeof(void*)); -} - -// vim: set ts=4 sw=4: diff --git a/src/interface/class.c b/src/interface/class.c index a36e936..8327e89 100644 --- a/src/interface/class.c +++ b/src/interface/class.c @@ -70,7 +70,7 @@ classDelete(void ** object) void * classClone(void * _object) { - class_ptr class = class_getClass(_object); + class_ptr class = GET_CLASS(_object); void * object = calloc(1, class->object_size + sizeof(void*)); * (class_ptr *)object = class;