All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty.tools.dotc.util.CharBuffer.scala Maven / Gradle / Ivy

There is a newer version: 3.6.4-RC1-bin-20241220-0bfa1af-NIGHTLY
Show newest version
package dotty.tools
package dotc
package util

/** A character buffer that exposes the internal array for reading.
 *  That way we can avoid copying when converting to names.
 */
class CharBuffer(initialSize: Int = 1024):
  private var cs: Array[Char] = new Array[Char](initialSize)
  private var len: Int = 0

  def append(ch: Char): Unit =
    if len == cs.length then
      val cs1 = new Array[Char](len * 2)
      Array.copy(cs, 0, cs1, 0, len)
      cs = cs1
    cs(len) = ch
    len += 1

  def chars = cs
  def length = len
  def isEmpty: Boolean = len == 0
  def last: Char = cs(len - 1)
  def clear(): Unit = len = 0

  override def toString = String(cs, 0, len)






© 2015 - 2025 Weber Informatics LLC | Privacy Policy