mirror of
https://github.com/go-i2p/gomobile-java.git
synced 2025-07-13 14:18:23 -04:00

Converting a Go string to a string suitable use a specialized function, UTF16Encode, that can encode the string directly to a malloc'ed buffer. That way, only two copies are made when strings are passed from Go to Java; once for UTF-8 to UTF-16 encoding and once for the creation of the Java String. This CL implements the same optimization in the other direction, with a UTF-16 to UTF-8 decoder implemented in C. Unfortunately, while calling into a Go decoder also saves the extra copy, the Cgo overhead makes the calls much slower for short strings. To alleviate the risk of introducing decoding bugs, I've added the tests from the encoding/utf16 package to SeqTest. As a sideeffect, both Java and ObjC now always copy strings, regardless of the argument mode. The cpy argument can therefore be removed from the string conversion functions. Furthermore, the modeRetained and modeReturned modes can be collapsed into just one. While we're here, delete a leftover function from seq/strings.go that wasn't removed when the old seq buffers went away. Benchmarks, as compared with benchstat over 5 runs: name old time/op new time/op delta JavaStringShort 11.4µs ±13% 11.6µs ± 4% ~ (p=0.859 n=10+5) JavaStringShortDirect 19.5µs ± 9% 20.3µs ± 2% +3.68% (p=0.019 n=9+5) JavaStringLong 103µs ± 8% 24µs ± 4% -77.13% (p=0.001 n=9+5) JavaStringLongDirect 113µs ± 9% 32µs ± 7% -71.63% (p=0.001 n=9+5) JavaStringShortUnicode 11.1µs ±16% 10.7µs ± 5% ~ (p=0.190 n=9+5) JavaStringShortUnicodeDirect 19.6µs ± 7% 20.2µs ± 1% +2.78% (p=0.029 n=9+5) JavaStringLongUnicode 97.1µs ± 9% 28.0µs ± 5% -71.17% (p=0.001 n=9+5) JavaStringLongUnicodeDirect 105µs ±10% 34µs ± 5% -67.23% (p=0.002 n=8+5) JavaStringRetShort 14.2µs ± 2% 13.9µs ± 1% -2.15% (p=0.006 n=8+5) JavaStringRetShortDirect 20.8µs ± 2% 20.4µs ± 2% ~ (p=0.065 n=8+5) JavaStringRetLong 42.2µs ± 9% 42.4µs ± 3% ~ (p=0.190 n=9+5) JavaStringRetLongDirect 51.2µs ±21% 50.8µs ± 8% ~ (p=0.518 n=9+5) GoStringShort 23.4µs ± 7% 22.5µs ± 3% -3.55% (p=0.019 n=9+5) GoStringLong 51.9µs ± 9% 53.1µs ± 3% ~ (p=0.240 n=9+5) GoStringShortUnicode 24.2µs ± 6% 22.8µs ± 1% -5.54% (p=0.002 n=9+5) GoStringLongUnicode 58.6µs ± 8% 57.6µs ± 3% ~ (p=0.518 n=9+5) GoStringRetShort 27.6µs ± 1% 23.2µs ± 2% -15.87% (p=0.003 n=7+5) GoStringRetLong 129µs ±12% 33µs ± 2% -74.03% (p=0.001 n=10+5) Change-Id: Icb9481981493ffca8defed9fb80a9433d6048937 Reviewed-on: https://go-review.googlesource.com/20250 Reviewed-by: David Crawshaw <crawshaw@golang.org>
170 lines
3.9 KiB
Plaintext
170 lines
3.9 KiB
Plaintext
// Package gomobile_bind is an autogenerated binder stub for package interfaces.
|
|
// gobind -lang=go interfaces
|
|
//
|
|
// File is generated by gobind. Do not edit.
|
|
package gomobile_bind
|
|
|
|
/*
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include "seq.h"
|
|
#include "interfaces.h"
|
|
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
_seq "golang.org/x/mobile/bind/seq"
|
|
"interfaces"
|
|
)
|
|
|
|
// suppress the error if seq ends up unused
|
|
var _ = _seq.FromRefNum
|
|
|
|
//export proxyinterfaces_Error_Err
|
|
func proxyinterfaces_Error_Err(refnum C.int32_t) C.nstring {
|
|
ref := _seq.FromRefNum(int32(refnum))
|
|
v := ref.Get().(interfaces.Error)
|
|
res_0 := v.Err()
|
|
var _res_0_str string
|
|
if res_0 == nil {
|
|
_res_0_str = ""
|
|
} else {
|
|
_res_0_str = res_0.Error()
|
|
}
|
|
_res_0 := encodeString(_res_0_str)
|
|
return _res_0
|
|
}
|
|
|
|
type proxyinterfaces_Error _seq.Ref
|
|
|
|
func (p *proxyinterfaces_Error) Err() error {
|
|
res := C.cproxyinterfaces_Error_Err(C.int32_t(p.Num))
|
|
_res_str := decodeString(res)
|
|
_res := toError(_res_str)
|
|
return _res
|
|
}
|
|
|
|
//export proxyinterfaces_I_Rand
|
|
func proxyinterfaces_I_Rand(refnum C.int32_t) C.int32_t {
|
|
ref := _seq.FromRefNum(int32(refnum))
|
|
v := ref.Get().(interfaces.I)
|
|
res_0 := v.Rand()
|
|
_res_0 := C.int32_t(res_0)
|
|
return _res_0
|
|
}
|
|
|
|
type proxyinterfaces_I _seq.Ref
|
|
|
|
func (p *proxyinterfaces_I) Rand() int32 {
|
|
res := C.cproxyinterfaces_I_Rand(C.int32_t(p.Num))
|
|
_res := int32(res)
|
|
return _res
|
|
}
|
|
|
|
//export proxyinterfaces_I1_J
|
|
func proxyinterfaces_I1_J(refnum C.int32_t) {
|
|
ref := _seq.FromRefNum(int32(refnum))
|
|
v := ref.Get().(interfaces.I1)
|
|
v.J()
|
|
}
|
|
|
|
//export proxyinterfaces_I2_G
|
|
func proxyinterfaces_I2_G(refnum C.int32_t) {
|
|
ref := _seq.FromRefNum(int32(refnum))
|
|
v := ref.Get().(interfaces.I2)
|
|
v.G()
|
|
}
|
|
|
|
//export proxyinterfaces_I3_F
|
|
func proxyinterfaces_I3_F(refnum C.int32_t) C.int32_t {
|
|
ref := _seq.FromRefNum(int32(refnum))
|
|
v := ref.Get().(interfaces.I3)
|
|
res_0 := v.F()
|
|
var _res_0 C.int32_t = _seq.NullRefNum
|
|
if res_0 != nil {
|
|
_res_0 = C.int32_t(_seq.ToRefNum(res_0))
|
|
}
|
|
return _res_0
|
|
}
|
|
|
|
type proxyinterfaces_I3 _seq.Ref
|
|
|
|
func (p *proxyinterfaces_I3) F() interfaces.I1 {
|
|
res := C.cproxyinterfaces_I3_F(C.int32_t(p.Num))
|
|
var _res interfaces.I1
|
|
_res_ref := _seq.FromRefNum(int32(res))
|
|
if _res_ref != nil {
|
|
if _res_ref.Num < 0 { // go object
|
|
_res = _res_ref.Get().(interfaces.I1)
|
|
}
|
|
}
|
|
return _res
|
|
}
|
|
|
|
//export proxyinterfaces_WithParam_HasParam
|
|
func proxyinterfaces_WithParam_HasParam(refnum C.int32_t, param_p0 C.char) {
|
|
ref := _seq.FromRefNum(int32(refnum))
|
|
v := ref.Get().(interfaces.WithParam)
|
|
_param_p0 := param_p0 != 0
|
|
v.HasParam(_param_p0)
|
|
}
|
|
|
|
type proxyinterfaces_WithParam _seq.Ref
|
|
|
|
func (p *proxyinterfaces_WithParam) HasParam(param_p0 bool) {
|
|
var _param_p0 C.char = 0
|
|
if param_p0 {
|
|
_param_p0 = 1
|
|
}
|
|
C.cproxyinterfaces_WithParam_HasParam(C.int32_t(p.Num), _param_p0)
|
|
}
|
|
|
|
//export proxyinterfaces__Add3
|
|
func proxyinterfaces__Add3(param_r C.int32_t) C.int32_t {
|
|
var _param_r interfaces.I
|
|
_param_r_ref := _seq.FromRefNum(int32(param_r))
|
|
if _param_r_ref != nil {
|
|
if _param_r_ref.Num < 0 { // go object
|
|
_param_r = _param_r_ref.Get().(interfaces.I)
|
|
} else { // foreign object
|
|
_param_r = (*proxyinterfaces_I)(_param_r_ref)
|
|
}
|
|
}
|
|
res_0 := interfaces.Add3(_param_r)
|
|
_res_0 := C.int32_t(res_0)
|
|
return _res_0
|
|
}
|
|
|
|
//export proxyinterfaces__CallErr
|
|
func proxyinterfaces__CallErr(param_e C.int32_t) C.nstring {
|
|
var _param_e interfaces.Error
|
|
_param_e_ref := _seq.FromRefNum(int32(param_e))
|
|
if _param_e_ref != nil {
|
|
if _param_e_ref.Num < 0 { // go object
|
|
_param_e = _param_e_ref.Get().(interfaces.Error)
|
|
} else { // foreign object
|
|
_param_e = (*proxyinterfaces_Error)(_param_e_ref)
|
|
}
|
|
}
|
|
res_0 := interfaces.CallErr(_param_e)
|
|
var _res_0_str string
|
|
if res_0 == nil {
|
|
_res_0_str = ""
|
|
} else {
|
|
_res_0_str = res_0.Error()
|
|
}
|
|
_res_0 := encodeString(_res_0_str)
|
|
return _res_0
|
|
}
|
|
|
|
//export proxyinterfaces__Seven
|
|
func proxyinterfaces__Seven() C.int32_t {
|
|
res_0 := interfaces.Seven()
|
|
var _res_0 C.int32_t = _seq.NullRefNum
|
|
if res_0 != nil {
|
|
_res_0 = C.int32_t(_seq.ToRefNum(res_0))
|
|
}
|
|
return _res_0
|
|
}
|