Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build ignore | 5 // +build ignore |
6 | 6 |
7 // Unicode table generator. | 7 // Unicode table generator. |
8 // Data read from the web. | 8 // Data read from the web. |
9 | 9 |
10 package main | 10 package main |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 } | 546 } |
547 rt.add(uint32(lo), uint32(hi), uint32(stride)) | 547 rt.add(uint32(lo), uint32(hi), uint32(stride)) |
548 // next range: start looking where this range ends | 548 // next range: start looking where this range ends |
549 next = hi + 1 | 549 next = hi + 1 |
550 } | 550 } |
551 fmt.Print(header) | 551 fmt.Print(header) |
552 fmt.Print(rt.String()) | 552 fmt.Print(rt.String()) |
553 fmt.Print("}\n") | 553 fmt.Print("}\n") |
554 } | 554 } |
555 | 555 |
556 // allRange[16|32] accumulate all ranges that will be used | 556 // As of Go 1.3, the gc toolchain gives every static array |
r
2014/03/25 02:14:26
if you're going to use a regexp, use a regexp.
al
josharian
2014/03/25 16:00:15
Ack (in both senses of the word). Fixed.
| |
557 // into shared backing arrays. This makes binaries smaller. | 557 // its own symbol in the binary, with concomitant symbol |
r
2014/03/25 02:14:26
what does "This" refer to?
i would prefer a more
josharian
2014/03/25 16:00:15
Done.
| |
558 // overhead and padding. When there are many small static | |
559 // slices, this adds noticeably to the binary size; each | |
560 // static slice is given its own static backing array. | |
561 // To save space, we create shared backing arrays that | |
562 // all RangeTables can slice into for their Range16 and | |
563 // Range32 slices. See also issue 7599. | |
558 var ( | 564 var ( |
559 allRange16 []unicode.Range16 | 565 allRange16 []unicode.Range16 |
560 allRange32 []unicode.Range32 | 566 allRange32 []unicode.Range32 |
561 ) | 567 ) |
562 | 568 |
563 // rangeTable is a single code-gen *RangeTable. | 569 // rangeTable is a single code-gen *RangeTable. |
564 // Additions to a rangeTable modify allRange[16|32]. | 570 // Additions to a rangeTable modify the allRange tables. |
r
2014/03/25 02:14:26
modify the allRange tables.
josharian
2014/03/25 16:00:15
Done.
| |
565 // As a result, new rangeTables must not be created or | 571 // As a result, new rangeTables must not be created or |
566 // used until previous rangeTables are done being used. | 572 // used until previous rangeTables are complete. |
r
2014/03/25 02:14:26
s/done being used/complete/
josharian
2014/03/25 16:00:15
Done.
| |
567 type rangeTable struct { | 573 type rangeTable struct { |
568 min16 int // first offset into allRange16 | 574 min16 int // first offset into allRange16 |
569 min32 int // first offset into allRange32 | 575 min32 int // first offset into allRange32 |
570 latinOffset int | 576 latinOffset int |
571 } | 577 } |
572 | 578 |
573 func newRangeTable() *rangeTable { | 579 func newRangeTable() *rangeTable { |
574 return &rangeTable{min16: len(allRange16), min32: len(allRange32)} | 580 return &rangeTable{min16: len(allRange16), min32: len(allRange32)} |
575 } | 581 } |
576 | 582 |
577 func (r *rangeTable) add(lo, hi, stride uint32) { | 583 func (r *rangeTable) add(lo, hi, stride uint32) { |
578 if lo < 1<<16 && hi >= 1<<16 { | 584 if lo < 1<<16 && hi >= 1<<16 { |
579 if lo+stride != hi { | 585 if lo+stride != hi { |
580 logger.Fatalf("unexpected straddle: %U %U %d", lo, hi, s tride) | 586 logger.Fatalf("unexpected straddle: %U %U %d", lo, hi, s tride) |
581 } | 587 } |
588 if lo == 0xFFFF { | |
589 logger.Fatal("unexpected lo: U+FFFF") | |
590 } | |
582 // No range contains U+FFFF as an instance, so split | 591 // No range contains U+FFFF as an instance, so split |
r
2014/03/25 02:14:26
you need to verify this condition because it will
josharian
2014/03/25 16:00:15
Done.
| |
583 // the range into two entries. That way we can maintain | 592 // the range into two entries. That way we can maintain |
584 » » // the invariant that R32 contains only >= 1<<16. | 593 » » // the invariant that allRange32 contains only >= 1<<16. |
r
2014/03/25 02:14:26
s/R32/allRange32/
josharian
2014/03/25 16:00:15
Done.
| |
585 r.add(lo, lo, 1) | 594 r.add(lo, lo, 1) |
586 r.add(lo+stride, hi, stride) | 595 r.add(lo+stride, hi, stride) |
587 return | 596 return |
588 } | 597 } |
589 if hi <= unicode.MaxLatin1 { | 598 if hi <= unicode.MaxLatin1 { |
590 r.latinOffset++ | 599 r.latinOffset++ |
591 } | 600 } |
592 if lo < 1<<16 { | 601 if lo < 1<<16 { |
593 allRange16 = append(allRange16, unicode.Range16{uint16(lo), uint 16(hi), uint16(stride)}) | 602 allRange16 = append(allRange16, unicode.Range16{uint16(lo), uint 16(hi), uint16(stride)}) |
594 } else { | 603 } else { |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1341 range16Count := len(allRange16) | 1350 range16Count := len(allRange16) |
1342 range32Count := len(allRange32) | 1351 range32Count := len(allRange32) |
1343 fmt.Println() | 1352 fmt.Println() |
1344 fmt.Printf("// Range entries: %d 16-bit, %d 32-bit, %d total.\n", range1 6Count, range32Count, range16Count+range32Count) | 1353 fmt.Printf("// Range entries: %d 16-bit, %d 32-bit, %d total.\n", range1 6Count, range32Count, range16Count+range32Count) |
1345 range16Bytes := range16Count * 3 * 2 | 1354 range16Bytes := range16Count * 3 * 2 |
1346 range32Bytes := range32Count * 3 * 4 | 1355 range32Bytes := range32Count * 3 * 4 |
1347 fmt.Printf("// Range bytes: %d 16-bit, %d 32-bit, %d total.\n", range16B ytes, range32Bytes, range16Bytes+range32Bytes) | 1356 fmt.Printf("// Range bytes: %d 16-bit, %d 32-bit, %d total.\n", range16B ytes, range32Bytes, range16Bytes+range32Bytes) |
1348 fmt.Println() | 1357 fmt.Println() |
1349 fmt.Printf("// Fold orbit bytes: %d pairs, %d bytes\n", foldPairCount, f oldPairCount*2*2) | 1358 fmt.Printf("// Fold orbit bytes: %d pairs, %d bytes\n", foldPairCount, f oldPairCount*2*2) |
1350 } | 1359 } |
LEFT | RIGHT |