On Thu, Aug 29, 2013 at 4:29 AM, Bennie Kloosteman <[email protected]>wrote:

> var str = new FastString<N:5>;
>

Why this? if fixed-sized-strings are safe types, then can be used directly
in parametrics. Something like this:

interface String {
   int length { get; }
   byte[] rawData { get; }
   // .. more methods..
}
class StringUCS2Impl<T> : String where T : fixed byte[] {
   T basedata
   int some_other_field;

   static String MakeString(int size) {
        return (String)new StringUCS2Impl<byte[size]>();
   }
   // .. UCS2 specific string handling methods
}

This has lots of benefit, since we can now define our own String
implementation which is compatible with all existing string methods.
However, there are some caveats.

(1) This presumes a bit more JVM centric view of the world, where we expect
Hotspot to inline all these interface virtual calls. I'm not sure CLR is as
good at this.

(2) The naive approach is going to parametrically instantiate for each SIZE
of a string, not each type of string, because the size affects the offset
of some_other_field. I think this may be why they punted safe
fixed-size-strings. In order to share parametric instantiations, we'd need
some kind of fancy offset indirection for a single instantiation. Perhaps
shifting all fixed-size arrays to the bottom, and then added
offset-and-length information as static class fields.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to