Commit 87b2b4ed authored by Lysander Trischler's avatar Lysander Trischler
Browse files

Don't duplicate mentions, links and tags over the wire

It's sufficient to let the Python wrapper reconstruct the lists from the
parsed elements. No need to pass all these data twice over the C bridge.
parent e1b4c506
......@@ -218,12 +218,6 @@ class _Twt(ctypes.Structure):
("created", ctypes.c_char_p),
("hash", ctypes.c_char_p),
("subject", ctypes.POINTER(_Subject)),
("mentions", ctypes.POINTER(ctypes.POINTER(_Twter))),
("mentions_len", ctypes.c_int),
("links", ctypes.POINTER(ctypes.POINTER(_Link))),
("links_len", ctypes.c_int),
("tags", ctypes.POINTER(ctypes.POINTER(_Link))),
("tags_len", ctypes.c_int),
("elems_len", ctypes.c_int),
("elems", ctypes.POINTER(ctypes.POINTER(_Elem)))]
......@@ -239,20 +233,21 @@ class _Twt(ctypes.Structure):
twt.subject = self.subject.contents.to_python()
twt.mentions = []
for i in range(self.mentions_len):
twt.mentions.append(self.mentions[i].contents.to_python())
twt.links = []
for i in range(self.links_len):
twt.links.append(self.links[i].contents.to_python())
twt.tags = []
for i in range(self.tags_len):
twt.tags.append(self.tags[i].contents.to_python())
twt.elems = []
for i in range(self.elems_len):
twt.elems.append(self.elems[i].contents.to_python())
elem = self.elems[i].contents.to_python()
twt.elems.append(elem)
if isinstance(elem, Twter):
twt.mentions.append(elem)
elif isinstance(elem, Link):
if elem.type == Link.TAG:
twt.tags.append(elem)
else:
twt.links.append(elem)
elif isinstance(elem, Subject) and elem.tag:
twt.tags.append(elem.tag)
return twt
......
......@@ -36,12 +36,6 @@ struct twt {
char *created;
char *hash;
struct subject *subject;
struct twter *mentions;
int mentions_len;
struct link *links;
int links_len;
struct link *tags;
int tags_len;
int elems_len;
struct elem *elems;
};
......@@ -157,16 +151,6 @@ func freeTwter(t *C.struct_twter) {
}
}
func freeTwters(t *C.struct_twter, length C.int) {
if t != nil {
twters := (*[arraySize]*C.struct_twter)(unsafe.Pointer(t))
for i := 0; i < int(length); i++ {
freeTwter(twters[i])
}
C.free(unsafe.Pointer(t))
}
}
func convertTwt(t *lextwt.Twt) *C.struct_twt {
ptr := C.malloc(C.sizeof_struct_twt)
twt := (*C.struct_twt)(ptr)
......@@ -179,30 +163,6 @@ func convertTwt(t *lextwt.Twt) *C.struct_twt {
twt.subject = nil
}
mentionsPtr := C.malloc(C.size_t(len(t.Mentions())) * C.size_t(unsafe.Sizeof(uintptr(0))))
mentions := (*[arraySize]*C.struct_twter)(mentionsPtr)
for i, mention := range t.Mentions() {
mentions[i] = convertTwter(mention.Twter())
}
twt.mentions = (*C.struct_twter)(mentionsPtr)
twt.mentions_len = C.int(len(t.Mentions()))
linksPtr := C.malloc(C.size_t(len(t.Links())) * C.size_t(unsafe.Sizeof(uintptr(0))))
links := (*[arraySize]*C.struct_link)(linksPtr)
for i, link := range t.Links() {
links[i] = convertLink(link.(*lextwt.Link))
}
twt.links = (*C.struct_link)(linksPtr)
twt.links_len = C.int(len(t.Links()))
tagsPtr := C.malloc(C.size_t(len(t.Tags())) * C.size_t(unsafe.Sizeof(uintptr(0))))
tags := (*[arraySize]*C.struct_link)(tagsPtr)
for i, tag := range t.Tags() {
tags[i] = convertTagToLink(tag.(*lextwt.Tag))
}
twt.tags = (*C.struct_link)(tagsPtr)
twt.tags_len = C.int(len(t.Tags()))
elemsPtr := C.malloc(C.size_t(len(t.Elems())) * C.size_t(unsafe.Sizeof(uintptr(0))))
elems := (*[arraySize]*C.struct_elem)(elemsPtr)
for i, elem := range t.Elems() {
......@@ -220,9 +180,6 @@ func freeTwt(t *C.struct_twt) {
free_string(t.created)
free_string(t.hash)
freeSubject(t.subject)
freeTwters(t.mentions, t.mentions_len)
freeLinks(t.links, t.links_len)
freeLinks(t.tags, t.tags_len)
freeElems(t.elems, t.elems_len)
C.free(unsafe.Pointer(t))
}
......@@ -298,16 +255,6 @@ func freeLink(l *C.struct_link) {
}
}
func freeLinks(l *C.struct_link, length C.int) {
if l != nil {
links := (*[arraySize]*C.struct_link)(unsafe.Pointer(l))
for i := 0; i < int(length); i++ {
freeLink(links[i])
}
C.free(unsafe.Pointer(l))
}
}
func newElem(elemType C.int, dataPointer unsafe.Pointer) *C.struct_elem {
ptr := C.malloc(C.sizeof_struct_elem)
elem := (*C.struct_elem)(ptr)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment