From 37b1c3309b0f63ebe20dc36ec5da34e9143a4205 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 10 Aug 2014 22:10:47 -0400 Subject: [PATCH] Stored table column numbers more efficiently on Mac OS X. --- redo/objc_darwin.h | 2 +- redo/table_darwin.go | 2 +- redo/table_darwin.m | 23 ++++++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/redo/objc_darwin.h b/redo/objc_darwin.h index de04f26..4066b5a 100644 --- a/redo/objc_darwin.h +++ b/redo/objc_darwin.h @@ -81,7 +81,7 @@ extern struct xsize tabPreferredSize(id); /* table_darwin.m */ extern id newTable(void); -extern void tableAppendColumn(id, char *); +extern void tableAppendColumn(id, intptr_t, char *); extern void tableUpdate(id); extern void tableMakeDataSource(id, void *); extern struct xsize tablePreferredSize(id); diff --git a/redo/table_darwin.go b/redo/table_darwin.go index 37fcdf4..c80dbdc 100644 --- a/redo/table_darwin.go +++ b/redo/table_darwin.go @@ -28,7 +28,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { C.tableMakeDataSource(t._id, unsafe.Pointer(t)) for i := 0; i < ty.NumField(); i++ { cname := C.CString(ty.Field(i).Name) - C.tableAppendColumn(t._id, cname) + C.tableAppendColumn(t._id, C.intptr_t(i), cname) C.free(unsafe.Pointer(cname)) // free now (not deferred) to conserve memory } return t diff --git a/redo/table_darwin.m b/redo/table_darwin.m index e679c1d..6da977d 100644 --- a/redo/table_darwin.m +++ b/redo/table_darwin.m @@ -6,6 +6,17 @@ #define toNSTableView(x) ((NSTableView *) (x)) +// NSTableColumn provides no provision to store an integer data +// it does provide an identifier tag, but that's a NSString, and I'd rather not risk the conversion overhead +@interface goTableColumn : NSTableColumn { +@public + intptr_t gocolnum; +} +@end + +@implementation goTableColumn +@end + @interface goTableDataSource : NSObject { @public void *gotable; @@ -23,9 +34,10 @@ { char *str; NSString *s; + intptr_t colnum; - // TODO there has to be a better way to get the column index - str = goTableDataSource_getValue(self->gotable, (intptr_t) row, (intptr_t) [[view tableColumns] indexOfObject:col]); + colnum = ((goTableColumn *) col)->gocolnum; + str = goTableDataSource_getValue(self->gotable, (intptr_t) row, colnum); s = [NSString stringWithUTF8String:str]; free(str); // allocated with C.CString() on the Go side return s; @@ -46,11 +58,12 @@ id newTable(void) return (id) t; } -void tableAppendColumn(id t, char *name) +void tableAppendColumn(id t, intptr_t colnum, char *name) { - NSTableColumn *c; + goTableColumn *c; - c = [[NSTableColumn alloc] initWithIdentifier:nil]; + c = [[goTableColumn alloc] initWithIdentifier:nil]; + c->gocolnum = colnum; [c setEditable:NO]; [[c headerCell] setStringValue:[NSString stringWithUTF8String:name]]; setSmallControlFont((id) [c headerCell]);