25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

143 satır
3.7 KiB

  1. //go:build !appengine && !noasm && gc
  2. // +build !appengine,!noasm,gc
  3. package s2
  4. // encodeBlock encodes a non-empty src to a guaranteed-large-enough dst. It
  5. // assumes that the varint-encoded length of the decompressed bytes has already
  6. // been written.
  7. //
  8. // It also assumes that:
  9. // len(dst) >= MaxEncodedLen(len(src)) &&
  10. // minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
  11. func encodeBlock(dst, src []byte) (d int) {
  12. const (
  13. // Use 12 bit table when less than...
  14. limit12B = 16 << 10
  15. // Use 10 bit table when less than...
  16. limit10B = 4 << 10
  17. // Use 8 bit table when less than...
  18. limit8B = 512
  19. )
  20. if len(src) >= 4<<20 {
  21. return encodeBlockAsm(dst, src)
  22. }
  23. if len(src) >= limit12B {
  24. return encodeBlockAsm4MB(dst, src)
  25. }
  26. if len(src) >= limit10B {
  27. return encodeBlockAsm12B(dst, src)
  28. }
  29. if len(src) >= limit8B {
  30. return encodeBlockAsm10B(dst, src)
  31. }
  32. if len(src) < minNonLiteralBlockSize {
  33. return 0
  34. }
  35. return encodeBlockAsm8B(dst, src)
  36. }
  37. // encodeBlockBetter encodes a non-empty src to a guaranteed-large-enough dst. It
  38. // assumes that the varint-encoded length of the decompressed bytes has already
  39. // been written.
  40. //
  41. // It also assumes that:
  42. // len(dst) >= MaxEncodedLen(len(src)) &&
  43. // minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
  44. func encodeBlockBetter(dst, src []byte) (d int) {
  45. const (
  46. // Use 12 bit table when less than...
  47. limit12B = 16 << 10
  48. // Use 10 bit table when less than...
  49. limit10B = 4 << 10
  50. // Use 8 bit table when less than...
  51. limit8B = 512
  52. )
  53. if len(src) > 4<<20 {
  54. return encodeBetterBlockAsm(dst, src)
  55. }
  56. if len(src) >= limit12B {
  57. return encodeBetterBlockAsm4MB(dst, src)
  58. }
  59. if len(src) >= limit10B {
  60. return encodeBetterBlockAsm12B(dst, src)
  61. }
  62. if len(src) >= limit8B {
  63. return encodeBetterBlockAsm10B(dst, src)
  64. }
  65. if len(src) < minNonLiteralBlockSize {
  66. return 0
  67. }
  68. return encodeBetterBlockAsm8B(dst, src)
  69. }
  70. // encodeBlockSnappy encodes a non-empty src to a guaranteed-large-enough dst. It
  71. // assumes that the varint-encoded length of the decompressed bytes has already
  72. // been written.
  73. //
  74. // It also assumes that:
  75. // len(dst) >= MaxEncodedLen(len(src)) &&
  76. // minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
  77. func encodeBlockSnappy(dst, src []byte) (d int) {
  78. const (
  79. // Use 12 bit table when less than...
  80. limit12B = 16 << 10
  81. // Use 10 bit table when less than...
  82. limit10B = 4 << 10
  83. // Use 8 bit table when less than...
  84. limit8B = 512
  85. )
  86. if len(src) >= 64<<10 {
  87. return encodeSnappyBlockAsm(dst, src)
  88. }
  89. if len(src) >= limit12B {
  90. return encodeSnappyBlockAsm64K(dst, src)
  91. }
  92. if len(src) >= limit10B {
  93. return encodeSnappyBlockAsm12B(dst, src)
  94. }
  95. if len(src) >= limit8B {
  96. return encodeSnappyBlockAsm10B(dst, src)
  97. }
  98. if len(src) < minNonLiteralBlockSize {
  99. return 0
  100. }
  101. return encodeSnappyBlockAsm8B(dst, src)
  102. }
  103. // encodeBlockSnappy encodes a non-empty src to a guaranteed-large-enough dst. It
  104. // assumes that the varint-encoded length of the decompressed bytes has already
  105. // been written.
  106. //
  107. // It also assumes that:
  108. // len(dst) >= MaxEncodedLen(len(src)) &&
  109. // minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
  110. func encodeBlockBetterSnappy(dst, src []byte) (d int) {
  111. const (
  112. // Use 12 bit table when less than...
  113. limit12B = 16 << 10
  114. // Use 10 bit table when less than...
  115. limit10B = 4 << 10
  116. // Use 8 bit table when less than...
  117. limit8B = 512
  118. )
  119. if len(src) >= 64<<10 {
  120. return encodeSnappyBetterBlockAsm(dst, src)
  121. }
  122. if len(src) >= limit12B {
  123. return encodeSnappyBetterBlockAsm64K(dst, src)
  124. }
  125. if len(src) >= limit10B {
  126. return encodeSnappyBetterBlockAsm12B(dst, src)
  127. }
  128. if len(src) >= limit8B {
  129. return encodeSnappyBetterBlockAsm10B(dst, src)
  130. }
  131. if len(src) < minNonLiteralBlockSize {
  132. return 0
  133. }
  134. return encodeSnappyBetterBlockAsm8B(dst, src)
  135. }