mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
trie parameters and fix a few bugs The bugs did not affect correctness of the particular instance of trie created for grapheme cluster property, because trie parameters that were confused with each other happened to be equal. Also, fix a trie size bug: we were creating a trie large enough to store information for 0x200000 code points, but there are only 0x10ffff. It saved only 15 bytes in the grapheme cluster tree, because that extra information was compressed with some supplementary planes that also had default values. This also improved trie generation time by almost 2x. Swift SVN r19457
133 lines
4.2 KiB
C++
133 lines
4.2 KiB
C++
//===- UnicodeExtendedGraphemeClusters.cpp.gyb ------------------*- c++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
%{
|
|
|
|
# FIXME: this table should be moved to a Swift file in stdlib. Unfortunately,
|
|
# in Swift we don't have a way to statically initialize arrays.
|
|
|
|
from GYBUnicodeDataUtils import *
|
|
|
|
grapheme_cluster_break_property_table = \
|
|
GraphemeClusterBreakPropertyTable(unicodeGraphemeBreakPropertyFile)
|
|
|
|
trie_generator = UnicodeTrieGenerator()
|
|
trie_generator.create_tables()
|
|
trie_generator.fill_from_unicode_property(grapheme_cluster_break_property_table)
|
|
trie_generator.verify(grapheme_cluster_break_property_table)
|
|
|
|
}%
|
|
|
|
/// Before compression:
|
|
/// BMP_lookup: ${len(trie_generator.BMP_lookup)}
|
|
/// BMP_data: ${len(trie_generator.BMP_data)} x ${len(trie_generator.BMP_data[0])}
|
|
/// supp_lookup1: ${len(trie_generator.supp_lookup1)}
|
|
/// supp_lookup2: ${len(trie_generator.supp_lookup2)} x ${len(trie_generator.supp_lookup2[0])}
|
|
/// supp_data: ${len(trie_generator.supp_data)} x ${len(trie_generator.supp_data[0])}
|
|
|
|
%{
|
|
|
|
trie_generator.freeze()
|
|
trie_generator.verify(grapheme_cluster_break_property_table)
|
|
|
|
}%
|
|
|
|
/// After compression:
|
|
/// BMP_lookup: ${len(trie_generator.BMP_lookup)}
|
|
/// BMP_data: ${len(trie_generator.BMP_data)} x ${len(trie_generator.BMP_data[0])}
|
|
/// supp_lookup1: ${len(trie_generator.supp_lookup1)}
|
|
/// supp_lookup2: ${len(trie_generator.supp_lookup2)} x ${len(trie_generator.supp_lookup2[0])}
|
|
/// supp_data: ${len(trie_generator.supp_data)} x ${len(trie_generator.supp_data[0])}
|
|
|
|
%{
|
|
|
|
trie_generator.serialize(grapheme_cluster_break_property_table)
|
|
|
|
}%
|
|
|
|
#include <stdint.h>
|
|
|
|
const uint8_t _swift_stdlib_GraphemeClusterBreakPropertyTrieImpl[] = {
|
|
% for byte in trie_generator.trie_bytes:
|
|
${byte},
|
|
% end
|
|
};
|
|
|
|
extern "C"
|
|
const uint8_t *_swift_stdlib_GraphemeClusterBreakPropertyTrie =
|
|
_swift_stdlib_GraphemeClusterBreakPropertyTrieImpl;
|
|
|
|
struct _swift_stdlib_GraphemeClusterBreakPropertyTrieMetadataTy {
|
|
unsigned BMPFirstLevelIndexBits;
|
|
unsigned BMPDataOffsetBits;
|
|
unsigned SuppFirstLevelIndexBits;
|
|
unsigned SuppSecondLevelIndexBits;
|
|
unsigned SuppDataOffsetBits;
|
|
|
|
unsigned BMPLookupBytesPerEntry;
|
|
unsigned BMPDataBytesPerEntry;
|
|
unsigned SuppLookup1BytesPerEntry;
|
|
unsigned SuppLookup2BytesPerEntry;
|
|
unsigned SuppDataBytesPerEntry;
|
|
|
|
unsigned TrieSize;
|
|
|
|
unsigned BMPLookupBytesOffset;
|
|
unsigned BMPDataBytesOffset;
|
|
unsigned SuppLookup1BytesOffset;
|
|
unsigned SuppLookup2BytesOffset;
|
|
unsigned SuppDataBytesOffset;
|
|
};
|
|
|
|
extern "C" const struct _swift_stdlib_GraphemeClusterBreakPropertyTrieMetadataTy
|
|
_swift_stdlib_GraphemeClusterBreakPropertyTrieMetadata = {
|
|
${trie_generator.BMP_first_level_index_bits},
|
|
${trie_generator.BMP_data_offset_bits},
|
|
${trie_generator.supp_first_level_index_bits},
|
|
${trie_generator.supp_second_level_index_bits},
|
|
${trie_generator.supp_data_offset_bits},
|
|
|
|
${trie_generator.BMP_lookup_bytes_per_entry},
|
|
${trie_generator.BMP_data_bytes_per_entry},
|
|
${trie_generator.supp_lookup1_bytes_per_entry},
|
|
${trie_generator.supp_lookup2_bytes_per_entry},
|
|
${trie_generator.supp_data_bytes_per_entry},
|
|
|
|
${len(trie_generator.trie_bytes)},
|
|
|
|
${trie_generator.BMP_lookup_bytes_offset},
|
|
${trie_generator.BMP_data_bytes_offset},
|
|
${trie_generator.supp_lookup1_bytes_offset},
|
|
${trie_generator.supp_lookup2_bytes_offset},
|
|
${trie_generator.supp_data_bytes_offset},
|
|
};
|
|
|
|
%{
|
|
|
|
extended_grapheme_cluster_rules_matrix = \
|
|
get_extended_grapheme_cluster_rules_matrix(grapheme_cluster_break_property_table)
|
|
|
|
}%
|
|
|
|
const uint16_t _swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrixImpl[] = {
|
|
% for row in get_extended_grapheme_cluster_rules_matrix(grapheme_cluster_break_property_table):
|
|
${row},
|
|
% end
|
|
};
|
|
|
|
const uint16_t *_swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrix =
|
|
_swift_stdlib_ExtendedGraphemeClusterNoBoundaryRulesMatrixImpl;
|
|
|
|
// ${'Local Variables'}:
|
|
// eval: (read-only-mode 1)
|
|
// End:
|