diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-06-17 18:38:21 +0400 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-06-26 22:43:45 +0400 |
commit | 4e913309b92138cdc6ff31fbce4e8afa2ab5458e (patch) | |
tree | 8f702228144d8877d8f3d064300c8fdd1491d7b3 /src/transport.c | |
parent | 0a9a38e539b02d254ec37ce6c18bdda2aedaafc8 (diff) |
Move transports to an inheritance model
Rather than an 'private' pointer, make the private structures inherit
from the generic git_transport struct. This way, we only have to worry
about one memory allocation instead of two. The structures are so
simple that this may even make the code use less memory overall.
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/transport.c')
-rw-r--r-- | src/transport.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/transport.c b/src/transport.c index fb0dc32c9..59aecb4cf 100644 --- a/src/transport.c +++ b/src/transport.c @@ -17,7 +17,7 @@ struct { {NULL, 0} }; -static git_transport_cb transport_fill_fn(const char *url) +static git_transport_cb transport_new_fn(const char *url) { int i = 0; @@ -43,7 +43,7 @@ static git_transport_cb transport_fill_fn(const char *url) * Public API * **************/ -int git_transport_dummy(git_transport *GIT_UNUSED(transport)) +int git_transport_dummy(git_transport **GIT_UNUSED(transport)) { GIT_UNUSED_ARG(transport); return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry"); @@ -55,13 +55,11 @@ int git_transport_new(git_transport **out, git_repository *repo, const char *url git_transport *transport; int error; - fn = transport_fill_fn(url); + fn = transport_new_fn(url); - transport = git__malloc(sizeof(git_transport)); - if (transport == NULL) - return GIT_ENOMEM; - - memset(transport, 0x0, sizeof(git_transport)); + error = fn(&transport); + if (error < GIT_SUCCESS) + return git__rethrow(error, "Failed to create new transport"); transport->url = git__strdup(url); if (transport->url == NULL) @@ -69,10 +67,6 @@ int git_transport_new(git_transport **out, git_repository *repo, const char *url transport->repo = repo; - error = fn(transport); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create new transport"); - *out = transport; return GIT_SUCCESS; |