LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 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 package textproto | 5 package textproto |
6 | 6 |
7 import ( | 7 import ( |
8 "bufio" | 8 "bufio" |
9 "bytes" | 9 "bytes" |
10 "io" | 10 "io" |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 // The miss count is used to decide when to evict an entry that | 597 // The miss count is used to decide when to evict an entry that |
598 // is not pulling its weight, and should give its spot to a more | 598 // is not pulling its weight, and should give its spot to a more |
599 // common string of the same length. It is not threadsafe. | 599 // common string of the same length. It is not threadsafe. |
600 type valueCache [maxCachableLen]entry | 600 type valueCache [maxCachableLen]entry |
601 type entry struct { | 601 type entry struct { |
602 s string | 602 s string |
603 miss int32 | 603 miss int32 |
604 } | 604 } |
605 | 605 |
606 // maxCachableLen and maxMisses were chosen by looking at traces of | 606 // maxCachableLen and maxMisses were chosen by looking at traces of |
607 // headers arriving at a real-world webserver. | 607 // headers arriving at a real-world webserver. Only 18% of values |
| 608 // seen are larger than 40 characters. maxMisses 10 |
| 609 // gave .11% replacement rate, maxMisses 20 gives .06% with only |
| 610 // a .5% decrease in hit rate. Further increasing maxMisses decreases |
| 611 // the hit rate too much. |
608 const maxCachableLen = 40 | 612 const maxCachableLen = 40 |
609 const maxMisses = 9 | 613 const maxMisses = 20 |
610 | 614 |
611 func eq(x []byte, y string) bool { | 615 func eq(x []byte, y string) bool { |
612 if len(x) != len(y) { | 616 if len(x) != len(y) { |
613 return false | 617 return false |
614 } | 618 } |
615 | 619 |
616 for i, b := range x { | 620 for i, b := range x { |
617 if y[i] != b { | 621 if y[i] != b { |
618 return false | 622 return false |
619 } | 623 } |
(...skipping 18 matching lines...) Expand all Loading... |
638 if eq(x, it.s) { | 642 if eq(x, it.s) { |
639 if it.miss != 0 { | 643 if it.miss != 0 { |
640 it.miss = 0 | 644 it.miss = 0 |
641 } | 645 } |
642 return it.s | 646 return it.s |
643 } | 647 } |
644 | 648 |
645 it.miss++ | 649 it.miss++ |
646 return string(x) | 650 return string(x) |
647 } | 651 } |
LEFT | RIGHT |