【问题标题】:Why does it take so long to have the IDE update from what I paste in?为什么从我粘贴的内容中更新 IDE 需要这么长时间?
【发布时间】:2020-01-19 20:06:33
【问题描述】:

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

我的问题是:“为什么我的代码需要 30 多秒才能更新我使用自动填充管理器粘贴的内容?这是因为我有太多 if、else if 语句和定义的变量吗?”

//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")
        }

从我的代码中,您可以看到我粘贴的内容(请参见下面的“之前”图片),但经过一番思考,IDE 会更新为之后图片中显示的内容(请参见下面的“之后”图片)。我相信这可能是由于声明太多,但需要一些确认,并且可能需要一些关于我应该如何开始清理它的输入。

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

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

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

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

谢谢!

【问题讨论】:

    标签: android android-studio kotlin android-autofill-manager


    【解决方案1】:

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

    我做了什么:

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

    • 真正有帮助的另一件事是对某些 if 语句执行“清理代码”alt+enter 操作。

    • 显然,如果你有超过 4 个 if/else 语句,那么最后一个最有帮助的事情就是你应该只使用“When”语句。这个提供了最高的处理效率。

    【讨论】:

      猜你喜欢
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 2012-05-11
      • 1970-01-01
      相关资源
      最近更新 更多