Repository: square/okhttp
File: okhttp/src/main/kotlin/okhttp3/FormBody.kt (Kotlin)

Code before:
    var byteCount = 0L
    val buffer: Buffer = if (countBytes) Buffer() else sink!!.buffer

    for (i in 0 until encodedNames.size) {
      if (i > 0) buffer.writeByte('&'.toInt())
      buffer.writeUtf8(encodedNames[i])
      buffer.writeByte('='.toInt())
      buffer.writeUtf8(encodedValues[i])
    }

    if (countBytes) {
      byteCount = buffer.size
      buffer.clear()
    }

    return byteCount
  }

  class Builder @JvmOverloads constructor(private val charset: Charset? = null) {
    private val names = mutableListOf<String>()
    private val values = mutableListOf<String>()

    fun add(name: String, value: String) = apply {
      names += name.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          plusIsSpace = false,
          charset = charset
      )
      values += value.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          plusIsSpace = false,
          charset = charset
      )
    }

    fun addEncoded(name: String, value: String) = apply {
      names += name.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          alreadyEncoded = true,
          plusIsSpace = true,
          charset = charset
      )
      values += value.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          alreadyEncoded = true,
          plusIsSpace = true,
          charset = charset
      )
    }

    fun build(): FormBody = FormBody(names, values)

Review comment (suggestion):
This probably warrants an inline comment because the parameter name diverts from the intention. 

> @param plusIsSpace true to encode '+' as "%2B" if it is not already encoded.

But plusIsSpace, we just don't want the additional encoding.

Code after:
    var byteCount = 0L
    val buffer: Buffer = if (countBytes) Buffer() else sink!!.buffer

    for (i in 0 until encodedNames.size) {
      if (i > 0) buffer.writeByte('&'.toInt())
      buffer.writeUtf8(encodedNames[i])
      buffer.writeByte('='.toInt())
      buffer.writeUtf8(encodedValues[i])
    }

    if (countBytes) {
      byteCount = buffer.size
      buffer.clear()
    }

    return byteCount
  }

  class Builder @JvmOverloads constructor(private val charset: Charset? = null) {
    private val names = mutableListOf<String>()
    private val values = mutableListOf<String>()

    fun add(name: String, value: String) = apply {
      names += name.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          plusIsSpace = false, // plus is encoded as `%25`, space is encoded as plus
          charset = charset
      )
      values += value.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          plusIsSpace = false, // plus is encoded as `%25`, space is encoded as plus
          charset = charset
      )
    }

    fun addEncoded(name: String, value: String) = apply {
      names += name.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          alreadyEncoded = true,
          plusIsSpace = true,
          charset = charset
      )
      values += value.canonicalize(
          encodeSet = FORM_ENCODE_SET,
          alreadyEncoded = true,
          plusIsSpace = true,
          charset = charset
      )
    }

    fun build(): FormBody = FormBody(names, values)