Friday, June 16, 2017

Re: how to avoid JSNI



On Friday, June 16, 2017 at 10:38:09 AM UTC+2, Kirill Prazdnikov wrote:
Hi, since arrays are very slow (see https://github.com/gwtproject/gwt/issues/9501)

I have to use the following code to workaround:

public native byte[] createFastInt8(int size) /*-{
return new Int8Array(size);
}-*/;


The same time I want to avoid using JSNI to be future compatible so
How to do that is pure JsInterop ?

I believe you'd have to somehow use JSNI to cast the Int8Array to a byte[]; though I believe you could delegate that to jsinterop-base's Js.uncheckedCast().
AFAICT, there'll be a version of jsinterop-base without JSNI for use with j2cl (or possibly a version that'd work with both seamlessly, e.g. using super-source for GWT).

So that should work (you could also use the Int8Array from elemental2-core; and that one uses Js.cast() to cast to double[], so maybe you could use Js.cast() rather than Js.uncheckedCast()):

@JsType(isNative=true, namespace=JsPackage.GLOBAL)
public class Int8Array {
  public Int8Array(int size) {}
}

public static byte[] createFastInt8(int size) {
  return Js.uncheckedCast(new Int8Array(size));
}

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment