为什么我粘贴的 IDE 更新需要这么长时间?

Why does it take so long to have the IDE update from what I paste in?

我在代码中定义了 350 多个变量,用于 350 多个 if else 语句。

我的问题是:"why does my code take over 30 seconds to update what I paste in with the auto-fill manager? Is this because I have SO many if, else if statements and defined variables?"

//350+ defined initially
        var A244: String = "A244" //1

        var C219: String = "C219"  //2

        var A099: String = "A099"  //3

        var A169: String = "A169"  //4

        var A185: String = "A185"  //5
//    ETC ETC ETC...


//THEN THE 350+ ELSE IF STATMENTS BEGIN
     else if (A985.compareTo(punitstring) == 0) {
            val mtext2 = findViewById(R.id.textView4) as TextView
            mtext2.setText("4-5t DBB")
            val mtext3 = findViewById(R.id.textView8) as TextView
            mtext3.setText("Second")
        }
        else if (B024.compareTo(punitstring) == 0) {
            val mtext2 = findViewById(R.id.textView4) as TextView
            mtext2.setText("N/A0")
            val mtext3 = findViewById(R.id.textView8) as TextView
            mtext3.setText("First")
        }
        else if (B199.compareTo(punitstring) == 0) {
            val mtext2 = findViewById(R.id.textView4) as TextView
            mtext2.setText("N/A1")
            val mtext3 = findViewById(R.id.textView8) as TextView
            mtext3.setText("First")
        }
        else if (B215.compareTo(punitstring) == 0) {
            val mtext2 = findViewById(R.id.textView4) as TextView
            mtext2.setText("N/A2")
            val mtext3 = findViewById(R.id.textView8) as TextView
            mtext3.setText("First")
        }
        else if (B218.compareTo(punitstring) == 0) {
            val mtext2 = findViewById(R.id.textView4) as TextView
            mtext2.setText("DC Walkie")
            val mtext3 = findViewById(R.id.textView8) as TextView
            mtext3.setText("First")
        }
        else if (B219.compareTo(punitstring) == 0) {
            val mtext2 = findViewById(R.id.textView4) as TextView
            mtext2.setText("AC 3 WS")
            val mtext3 = findViewById(R.id.textView8) as TextView
            mtext3.setText("First")
        }

从我的代码中你可以看到我粘贴的内容(见下面的 "before" 图片),但经过一番思考 IDE 更新后图片中显示的内容(见 "after" 下图)。我相信这可能是由于太多的陈述,但需要一些确认,并且可能需要一些关于我应该如何开始清理它的输入。

之前,当 IDE 最初加载时: https://i.stack.imgur.com/OOBqR.jpg

在等待经理使用自动填充更新代码大约 30 秒后: https://i.stack.imgur.com/9LjwR.jpg

我已经尝试将最大数量的磁盘和 RAM space 分配给 IDE,但这没有帮助。

我的下一步可能是将所有 var 连接到一个特定的语句。不过,我不确定如何缩短 if 语句。

谢谢!

经过多次尝试,我自己解决了这个问题。

我做了什么:

  • 添加的每个变量都会导致警告,每次我更新一行代码时都需要在 IDE 中更新该警告。通过将警告设为 "val" 而不是 "var" 来修复警告,加快了速度。

  • 另一件真正有帮助的事情是对一些 if 语句执行 "cleanup code" alt+enter 操作。

  • 最后一个帮助最大的事情显然是如果你有超过 4 个 if/else 语句,你应该只使用 "When" 语句。这个处理效率最高