<commit_before>package scala

import scala.quoted._

object StagedTuple {
  import Tuple._
  import NonEmptyTuple._

  def toArrayStaged(tup: Expr[Tuple], size: Option[Int]): Expr[Array[Object]] = {
    if (!specialize) '(dynamicToArray(~tup))
    else size match {
      case Some(0) =>
        '($emptyArray)
      case Some(1) =>
        tup.as[Tuple1[Object]].bind(t => '(Array((~t)._1)))
      case Some(2) =>
        tup.as[Tuple2[Object, Object]].bind(t => '(Array((~t)._1, (~t)._2)))
      case Some(3) =>
        tup.as[Tuple3[Object, Object, Object]].bind(t => '(Array((~t)._1, (~t)._2, (~t)._3)))
      case Some(4) =>
        tup.as[Tuple4[Object, Object, Object, Object]].bind(t => '(Array((~t)._1, (~t)._2, (~t)._3, (~t)._4)))
      case Some(n) if n <= $MaxSpecialized =>
        '($toArray(~tup, ~n.toExpr))
      case Some(n) =>
        '((~tup.as[TupleXXL]).elems)
      case None =>
        '(dynamicToArray(~tup))
    }
  }

  def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int]): Expr[T] = {
    if (!specialize) '(dynamicFromArray[T](~xs))
    else {
      val tup: Expr[Any] = size match {
        case Some(0)  => '()
        case Some(1)  => '(Tuple1( (~xs)(0)))
        case Some(2)  => '(Tuple2( (~xs)(0), (~xs)(1)))
        case Some(3)  => '(Tuple3( (~xs)(0), (~xs)(1), (~xs)(2)))
        case Some(4)  => '(Tuple4( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3)))
        case Some(5)  => '(Tuple5( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4)))
        case Some(6)  => '(Tuple6( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4), (~xs)(5)))
        case Some(7)  => '(Tuple7( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4), (~xs)(5), (~xs)(6)))
        case Some(8)  => '(Tuple8( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4), (~xs)(5), (~xs)(6), (~xs)(7)))<commit_msg>Evaluate creation of array only once<commit_after>package scala

import scala.quoted._

object StagedTuple {
  import Tuple._
  import NonEmptyTuple._

  def toArrayStaged(tup: Expr[Tuple], size: Option[Int]): Expr[Array[Object]] = {
    if (!specialize) '(dynamicToArray(~tup))
    else size match {
      case Some(0) =>
        '($emptyArray)
      case Some(1) =>
        tup.as[Tuple1[Object]].bind(t => '(Array((~t)._1)))
      case Some(2) =>
        tup.as[Tuple2[Object, Object]].bind(t => '(Array((~t)._1, (~t)._2)))
      case Some(3) =>
        tup.as[Tuple3[Object, Object, Object]].bind(t => '(Array((~t)._1, (~t)._2, (~t)._3)))
      case Some(4) =>
        tup.as[Tuple4[Object, Object, Object, Object]].bind(t => '(Array((~t)._1, (~t)._2, (~t)._3, (~t)._4)))
      case Some(n) if n <= $MaxSpecialized =>
        '($toArray(~tup, ~n.toExpr))
      case Some(n) =>
        '((~tup.as[TupleXXL]).elems)
      case None =>
        '(dynamicToArray(~tup))
    }
  }

  def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int]): Expr[T] = {
    if (!specialize) '(dynamicFromArray[T](~xs))
    else xs.bind { xs =>
      val tup: Expr[Any] = size match {
        case Some(0)  => '()
        case Some(1)  => '(Tuple1( (~xs)(0)))
        case Some(2)  => '(Tuple2( (~xs)(0), (~xs)(1)))
        case Some(3)  => '(Tuple3( (~xs)(0), (~xs)(1), (~xs)(2)))
        case Some(4)  => '(Tuple4( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3)))
        case Some(5)  => '(Tuple5( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4)))
        case Some(6)  => '(Tuple6( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4), (~xs)(5)))
        case Some(7)  => '(Tuple7( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4), (~xs)(5), (~xs)(6)))
        case Some(8)  => '(Tuple8( (~xs)(0), (~xs)(1), (~xs)(2), (~xs)(3), (~xs)(4), (~xs)(5), (~xs)(6), (~xs)(7)))
{'fraction_non_alphanumeric': 0.2906190862395242, 'fraction_numerical': 0.038929440389294405, 'mean_word_length': 3.1760722347629797, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '965558', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1602, 'n_words': 296}