anchor.diff:    void writeStringTable(StringIndexer indexer) {
       _binaryOffsetForStringTable = getBufferOffset();
   
  +    // Containers for the utf8 encoded strings.
  +    final List<Uint8List> data = new List<Uint8List>();
  +    int totalLength = 0;
  +    const int minLength = 1 << 16;
  +    Uint8List buffer;
  +    int index = 0;
  +
       // Write the end offsets.
       writeUInt30(indexer.index.length);
  -    int endOffset = 0;
  -    List<List<int>> data =
  -        new List<List<int>>.filled(indexer.index.length, null);
  -    int i = 0;
  -    Utf8Encoder utf8Encoder = const Utf8Encoder();
       for (String key in indexer.index.keys) {
  -      List<int> utf8Bytes = utf8Encoder.convert(key);
  -      data[i] = utf8Bytes;
  -      endOffset += utf8Bytes.length;
  -      writeUInt30(endOffset);
  -      i++;
  +      if (key.isNotEmpty) {
  +        int requiredMinLength = key.length;
  +        int allocateMinLength = requiredMinLength * 3;
  +        int newIndex;
  +        while (true) {
  +          if (buffer == null || index + requiredMinLength >= buffer.length) {
  +            int newLength = minLength;
  +            if (allocateMinLength > newLength) newLength = allocateMinLength;
  +            if (buffer != null && index > 0) {
  +              data.add(new Uint8List.view(buffer.buffer, 0, index));
  +            }
  +            index = 0;
  +            buffer = new Uint8List(newLength);
  +          }
  +          newIndex = NotQuiteString.writeUtf8(buffer, index, key);
  +          if (newIndex != -1) break;
  +          requiredMinLength = allocateMinLength;
  +        }
  +        if (newIndex < 0) {
  +          // Utf8 encoding failed.
  +          if (buffer != null && index > 0) {
  +            data.add(new Uint8List.view(buffer.buffer, 0, index));
  +            buffer = null;
  +            index = 0;
  +          }
  +          List<int> converted = utf8.encoder.convert(key);
  +          data.add(converted);
  +          totalLength += converted.length;
  +        } else {
  +          totalLength += newIndex - index;
  +          index = newIndex;
  +        }
  +      }
  +      writeUInt30(totalLength);
  +    }
  +    if (buffer != null && index > 0) {
  +      data.add(Uint8List.view(buffer.buffer, 0, index));
       }
   
       // Write the UTF-8 encoded strings.
  -    for (var entry in data) {
  -      writeBytes(entry);
  +    for (int i = 0; i < data.length; ++i) {
  +      writeBytes(data[i]);
       }
     }
   
  
positive.code: library kernel.ast_to_binary;
  
  import 'dart:core' hide MapEntry;
  
  import '../ast.dart';
  import 'tag.dart';
  import 'dart:convert';
  import 'dart:io' show BytesBuilder;
  import 'dart:typed_data';
  
  
negative.code:               : null) ??
            new Source(<int>[], const <int>[]);
  
        String uriAsString = uri == null ? "" : "$uri";
        if (uriAsString.length * 3 < buffer.length) {
          int length = NotQuiteString.writeUtf8(buffer, 0, uriAsString);
          if (length < 0) {
            // Utf8 encoding failed.
            writeByteList(utf8.encoder.convert(uriAsString));
          } else {
            writeUInt30(length);
            for (int j = 0; j < length; j++) {
              writeByte(buffer[j]);
            }
          }
        } else {
          // Uncommon case with very long url.
          writeByteList(utf8.encoder.convert(uriAsString));
        }
  
        writeByteList(source.source);
        List<int> lineStarts = source.lineStarts;
        writeUInt30(lineStarts.length);
  