2
0
mirror of synced 2025-02-24 07:18:15 +00:00
mobile/bind/testdata/interfaces.objc.m.golden
Elias Naur 6fca37c69e mobile/bind: replace seq serialization with direct calls
The seq serialization machinery is a historic artifact from when Go
mobile code had to run in a separate process. Now that Go code is running
in-process, replace the explicit serialization with direct calls and pass
arguments on the stack.

The benefits are a much smaller bind runtime, much less garbage (and, in
Java, fewer objects with finalizers), less argument copying, and faster
cross-language calls.
The cost is a more complex generator, because some of the work from the
bind runtime is moved to generated code. Generated code now handles
conversion between Go and Java/ObjC types, multiple return values and memory
management of byte slice and string arguments.

To overcome the lack of calling C code between Go packages, all bound
packages now end up in the same (fake) package, "gomobile_bind", instead of
separate packages (go_<pkgname>). To avoid name clashes, the package name is
added as a prefix to generated functions and types.

Also, don't copy byte arrays passed to Go, saving call time and
allowing read([]byte)-style interfaces to foreign callers (#12113).

Finally, add support for nil interfaces and struct pointers to objc.

This is a large CL, but most of the changes stem from changing testdata.

The full benchcmp output on the CL/20095 benchmarks on my Nexus 5 is
reproduced below. Note that the savings for the JavaSlice* benchmarks are
skewed because byte slices are no longer copied before passing them to Go.

benchmark                                 old ns/op     new ns/op     delta
BenchmarkJavaEmpty                        26.0          19.0          -26.92%
BenchmarkJavaEmptyDirect                  23.0          22.0          -4.35%
BenchmarkJavaNoargs                       7685          2339          -69.56%
BenchmarkJavaNoargsDirect                 17405         8041          -53.80%
BenchmarkJavaOnearg                       26887         2366          -91.20%
BenchmarkJavaOneargDirect                 34266         7910          -76.92%
BenchmarkJavaOneret                       38325         2245          -94.14%
BenchmarkJavaOneretDirect                 46265         7708          -83.34%
BenchmarkJavaManyargs                     41720         2535          -93.92%
BenchmarkJavaManyargsDirect               51026         8373          -83.59%
BenchmarkJavaRefjava                      38139         21260         -44.26%
BenchmarkJavaRefjavaDirect                42706         28150         -34.08%
BenchmarkJavaRefgo                        34403         6843          -80.11%
BenchmarkJavaRefgoDirect                  40193         16582         -58.74%
BenchmarkJavaStringShort                  32366         9323          -71.20%
BenchmarkJavaStringShortDirect            41973         19118         -54.45%
BenchmarkJavaStringLong                   127879        94420         -26.16%
BenchmarkJavaStringLongDirect             133776        114760        -14.21%
BenchmarkJavaStringShortUnicode           32562         9221          -71.68%
BenchmarkJavaStringShortUnicodeDirect     41464         19094         -53.95%
BenchmarkJavaStringLongUnicode            131015        89401         -31.76%
BenchmarkJavaStringLongUnicodeDirect      134130        90786         -32.31%
BenchmarkJavaSliceShort                   42462         7538          -82.25%
BenchmarkJavaSliceShortDirect             52940         17017         -67.86%
BenchmarkJavaSliceLong                    138391        8466          -93.88%
BenchmarkJavaSliceLongDirect              205804        15666         -92.39%
BenchmarkGoEmpty                          3.00          3.00          +0.00%
BenchmarkGoEmptyDirect                    3.00          3.00          +0.00%
BenchmarkGoNoarg                          40342         13716         -66.00%
BenchmarkGoNoargDirect                    46691         13569         -70.94%
BenchmarkGoOnearg                         43529         13757         -68.40%
BenchmarkGoOneargDirect                   44867         14078         -68.62%
BenchmarkGoOneret                         45456         13559         -70.17%
BenchmarkGoOneretDirect                   44694         13442         -69.92%
BenchmarkGoRefjava                        55111         28071         -49.06%
BenchmarkGoRefjavaDirect                  60883         26872         -55.86%
BenchmarkGoRefgo                          57038         29223         -48.77%
BenchmarkGoRefgoDirect                    56153         27812         -50.47%
BenchmarkGoManyargs                       67967         17398         -74.40%
BenchmarkGoManyargsDirect                 60617         16998         -71.96%
BenchmarkGoStringShort                    57538         22600         -60.72%
BenchmarkGoStringShortDirect              52627         22704         -56.86%
BenchmarkGoStringLong                     128485        52530         -59.12%
BenchmarkGoStringLongDirect               138377        52079         -62.36%
BenchmarkGoStringShortUnicode             57062         22994         -59.70%
BenchmarkGoStringShortUnicodeDirect       62563         22938         -63.34%
BenchmarkGoStringLongUnicode              139913        55553         -60.29%
BenchmarkGoStringLongUnicodeDirect        150863        57791         -61.69%
BenchmarkGoSliceShort                     59279         20215         -65.90%
BenchmarkGoSliceShortDirect               60160         21136         -64.87%
BenchmarkGoSliceLong                      411225        301870        -26.59%
BenchmarkGoSliceLongDirect                399029        298915        -25.09%

Fixes golang/go#12619
Fixes golang/go#12113
Fixes golang/go#13033

Change-Id: I2b45e9e98a1248e3c23a5137f775f7364908bec7
Reviewed-on: https://go-review.googlesource.com/19821
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-03 15:03:45 +00:00

277 lines
6.0 KiB
Plaintext

// Objective-C API for talking to interfaces Go package.
// gobind -lang=objc interfaces
//
// File is generated by gobind. Do not edit.
#include "GoInterfaces.h"
#include <Foundation/Foundation.h>
#include "seq.h"
#include "_cgo_export.h"
static NSString* errDomain = @"go.interfaces";
@protocol goSeqRefInterface
-(GoSeqRef*) _ref;
@end
@class GoInterfacesError;
@class GoInterfacesI;
@class GoInterfacesI3;
@class GoInterfacesWithParam;
@interface GoInterfacesError : NSObject <GoInterfacesError> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
- (BOOL)err:(NSError**)error;
@end
@interface GoInterfacesI : NSObject <GoInterfacesI> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
- (int32_t)rand;
@end
@interface GoInterfacesI3 : NSObject <GoInterfacesI3> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
- (GoInterfacesI1*)f;
@end
@interface GoInterfacesWithParam : NSObject <GoInterfacesWithParam> {
}
@property(strong, readonly) id _ref;
- (id)initWithRef:(id)ref;
- (void)hasParam:(BOOL)p0;
@end
@implementation GoInterfacesError {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (BOOL)err:(NSError**)error {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxyinterfaces_Error_Err(refnum);
NSString *_error = go_seq_to_objc_string(r0);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
@end
@implementation GoInterfacesI {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (int32_t)rand {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t r0 = proxyinterfaces_I_Rand(refnum);
int32_t _ret0_ = (int32_t)r0;
return _ret0_;
}
@end
@implementation GoInterfacesI1 {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (void)j {
int32_t refnum = go_seq_go_to_refnum(self._ref);
proxyinterfaces_I1_J(refnum);
}
@end
@implementation GoInterfacesI2 {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (void)g {
int32_t refnum = go_seq_go_to_refnum(self._ref);
proxyinterfaces_I2_G(refnum);
}
@end
@implementation GoInterfacesI3 {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (GoInterfacesI1*)f {
int32_t refnum = go_seq_go_to_refnum(self._ref);
int32_t r0 = proxyinterfaces_I3_F(refnum);
GoInterfacesI1* _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoInterfacesI1 alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
@end
@implementation GoInterfacesWithParam {
}
- (id)initWithRef:(id)ref {
self = [super init];
if (self) { __ref = ref; }
return self;
}
- (void)hasParam:(BOOL)p0 {
int32_t refnum = go_seq_go_to_refnum(self._ref);
char _p0 = (char)p0;
proxyinterfaces_WithParam_HasParam(refnum, _p0);
}
@end
int32_t GoInterfacesAdd3(id<GoInterfacesI> r) {
int32_t _r;
if ([(id<NSObject>)(r) isKindOfClass:[GoInterfacesI class]]) {
id<goSeqRefInterface> r_proxy = (id<goSeqRefInterface>)(r);
_r = go_seq_go_to_refnum(r_proxy._ref);
} else {
_r = go_seq_to_refnum(r);
}
int32_t r0 = proxyinterfaces__Add3(_r);
int32_t _ret0_ = (int32_t)r0;
return _ret0_;
}
BOOL GoInterfacesCallErr(id<GoInterfacesError> e, NSError** error) {
int32_t _e;
if ([(id<NSObject>)(e) isKindOfClass:[GoInterfacesError class]]) {
id<goSeqRefInterface> e_proxy = (id<goSeqRefInterface>)(e);
_e = go_seq_go_to_refnum(e_proxy._ref);
} else {
_e = go_seq_to_refnum(e);
}
nstring r0 = proxyinterfaces__CallErr(_e);
NSString *_error = go_seq_to_objc_string(r0);
if ([_error length] != 0 && error != nil) {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:_error forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:errDomain code:1 userInfo:details];
}
return ([_error length] == 0);
}
id<GoInterfacesI> GoInterfacesSeven() {
int32_t r0 = proxyinterfaces__Seven();
id<GoInterfacesI> _ret0_ = nil;
GoSeqRef* _ret0__ref = go_seq_from_refnum(r0);
if (_ret0__ref != NULL) {
_ret0_ = _ret0__ref.obj;
if (_ret0_ == nil) {
_ret0_ = [[GoInterfacesI alloc] initWithRef:_ret0__ref];
}
}
return _ret0_;
}
nstring cproxyinterfaces_Error_Err(int32_t refnum) {
id<GoInterfacesError> o = go_seq_objc_from_refnum(refnum);
NSError* error = nil;
BOOL returnVal = [o err:&error];
NSString *error_str = nil;
if (!returnVal) {
error_str = [error localizedDescription];
if (error_str == nil || error_str.length == 0) {
error_str = @"gobind: unknown error";
}
}
nstring _error_str = go_seq_from_objc_string(error_str);
return _error_str;
}
int32_t cproxyinterfaces_I_Rand(int32_t refnum) {
id<GoInterfacesI> o = go_seq_objc_from_refnum(refnum);
int32_t returnVal = [o rand];
int32_t _returnVal = (int32_t)returnVal;
return _returnVal;
}
void cproxyinterfaces_I1_J(int32_t refnum) {
GoInterfacesI1* o = go_seq_objc_from_refnum(refnum);
[o j];
}
void cproxyinterfaces_I2_G(int32_t refnum) {
GoInterfacesI2* o = go_seq_objc_from_refnum(refnum);
[o g];
}
int32_t cproxyinterfaces_I3_F(int32_t refnum) {
id<GoInterfacesI3> o = go_seq_objc_from_refnum(refnum);
GoInterfacesI1* returnVal = [o f];
int32_t _returnVal;
if ([(id<NSObject>)(returnVal) isKindOfClass:[GoInterfacesI1 class]]) {
id<goSeqRefInterface> returnVal_proxy = (id<goSeqRefInterface>)(returnVal);
_returnVal = go_seq_go_to_refnum(returnVal_proxy._ref);
} else {
_returnVal = go_seq_to_refnum(returnVal);
}
return _returnVal;
}
void cproxyinterfaces_WithParam_HasParam(int32_t refnum, char p0) {
id<GoInterfacesWithParam> o = go_seq_objc_from_refnum(refnum);
BOOL _p0 = p0 ? YES : NO;
[o hasParam:_p0];
}
__attribute__((constructor)) static void init() {
init_seq();
}