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>
202 lines
3.5 KiB
Plaintext
202 lines
3.5 KiB
Plaintext
// Package gomobile_bind is an autogenerated binder stub for package vars.
|
|
// gobind -lang=go vars
|
|
//
|
|
// File is generated by gobind. Do not edit.
|
|
package gomobile_bind
|
|
|
|
/*
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include "seq.h"
|
|
#include "vars.h"
|
|
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
_seq "golang.org/x/mobile/bind/seq"
|
|
"vars"
|
|
)
|
|
|
|
// suppress the error if seq ends up unused
|
|
var _ = _seq.FromRefNum
|
|
|
|
type proxyS _seq.Ref
|
|
|
|
type proxyvars_I _seq.Ref
|
|
|
|
//export var_setvars_ABool
|
|
func var_setvars_ABool(v C.char) {
|
|
_v := v != 0
|
|
vars.ABool = _v
|
|
}
|
|
|
|
//export var_getvars_ABool
|
|
func var_getvars_ABool() C.char {
|
|
v := vars.ABool
|
|
var _v C.char = 0
|
|
if v {
|
|
_v = 1
|
|
}
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AFloat
|
|
func var_setvars_AFloat(v C.double) {
|
|
_v := float64(v)
|
|
vars.AFloat = _v
|
|
}
|
|
|
|
//export var_getvars_AFloat
|
|
func var_getvars_AFloat() C.double {
|
|
v := vars.AFloat
|
|
_v := C.double(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AFloat32
|
|
func var_setvars_AFloat32(v C.float) {
|
|
_v := float32(v)
|
|
vars.AFloat32 = _v
|
|
}
|
|
|
|
//export var_getvars_AFloat32
|
|
func var_getvars_AFloat32() C.float {
|
|
v := vars.AFloat32
|
|
_v := C.float(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AFloat64
|
|
func var_setvars_AFloat64(v C.double) {
|
|
_v := float64(v)
|
|
vars.AFloat64 = _v
|
|
}
|
|
|
|
//export var_getvars_AFloat64
|
|
func var_getvars_AFloat64() C.double {
|
|
v := vars.AFloat64
|
|
_v := C.double(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AString
|
|
func var_setvars_AString(v C.nstring) {
|
|
_v := decodeString(v)
|
|
vars.AString = _v
|
|
}
|
|
|
|
//export var_getvars_AString
|
|
func var_getvars_AString() C.nstring {
|
|
v := vars.AString
|
|
_v := encodeString(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AStructPtr
|
|
func var_setvars_AStructPtr(v C.int32_t) {
|
|
// Must be a Go object
|
|
_v_ref := _seq.FromRefNum(int32(v))
|
|
_v := _v_ref.Get().(*vars.S)
|
|
vars.AStructPtr = _v
|
|
}
|
|
|
|
//export var_getvars_AStructPtr
|
|
func var_getvars_AStructPtr() C.int32_t {
|
|
v := vars.AStructPtr
|
|
var _v C.int32_t = _seq.NullRefNum
|
|
if v != nil {
|
|
_v = C.int32_t(_seq.ToRefNum(v))
|
|
}
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AnInt
|
|
func var_setvars_AnInt(v C.nint) {
|
|
_v := int(v)
|
|
vars.AnInt = _v
|
|
}
|
|
|
|
//export var_getvars_AnInt
|
|
func var_getvars_AnInt() C.nint {
|
|
v := vars.AnInt
|
|
_v := C.nint(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AnInt16
|
|
func var_setvars_AnInt16(v C.int16_t) {
|
|
_v := int16(v)
|
|
vars.AnInt16 = _v
|
|
}
|
|
|
|
//export var_getvars_AnInt16
|
|
func var_getvars_AnInt16() C.int16_t {
|
|
v := vars.AnInt16
|
|
_v := C.int16_t(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AnInt32
|
|
func var_setvars_AnInt32(v C.int32_t) {
|
|
_v := int32(v)
|
|
vars.AnInt32 = _v
|
|
}
|
|
|
|
//export var_getvars_AnInt32
|
|
func var_getvars_AnInt32() C.int32_t {
|
|
v := vars.AnInt32
|
|
_v := C.int32_t(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AnInt64
|
|
func var_setvars_AnInt64(v C.int64_t) {
|
|
_v := int64(v)
|
|
vars.AnInt64 = _v
|
|
}
|
|
|
|
//export var_getvars_AnInt64
|
|
func var_getvars_AnInt64() C.int64_t {
|
|
v := vars.AnInt64
|
|
_v := C.int64_t(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AnInt8
|
|
func var_setvars_AnInt8(v C.int8_t) {
|
|
_v := int8(v)
|
|
vars.AnInt8 = _v
|
|
}
|
|
|
|
//export var_getvars_AnInt8
|
|
func var_getvars_AnInt8() C.int8_t {
|
|
v := vars.AnInt8
|
|
_v := C.int8_t(v)
|
|
return _v
|
|
}
|
|
|
|
//export var_setvars_AnInterface
|
|
func var_setvars_AnInterface(v C.int32_t) {
|
|
var _v vars.I
|
|
_v_ref := _seq.FromRefNum(int32(v))
|
|
if _v_ref != nil {
|
|
if _v_ref.Num < 0 { // go object
|
|
_v = _v_ref.Get().(vars.I)
|
|
} else { // foreign object
|
|
_v = (*proxyvars_I)(_v_ref)
|
|
}
|
|
}
|
|
vars.AnInterface = _v
|
|
}
|
|
|
|
//export var_getvars_AnInterface
|
|
func var_getvars_AnInterface() C.int32_t {
|
|
v := vars.AnInterface
|
|
var _v C.int32_t = _seq.NullRefNum
|
|
if v != nil {
|
|
_v = C.int32_t(_seq.ToRefNum(v))
|
|
}
|
|
return _v
|
|
}
|