Skip to content

源代码的一些不优雅的地方 #1

@j2go

Description

@j2go
  1. apijson.Log 这个类里使用了 System.err.println(TAG + ".DEBUG: " + msg);
    println 的实现中有锁,压测的时候会发现 qps 上不去
    public void println(String x) {
        synchronized (this) {
            print(x);
            newLine();
        }
    }

这里可以换成 slf4j 的实现,最终使用用什么日志实现可以交由下游应用自定义

  1. 大量的 bool == false 判断

  2. 在方法中使用循环拼接字符串
    比如 AbstractFunctionParser#toFunctionCallString

        public String toFunctionCallString(boolean useValue, String quote) {
            String s = getMethod() + "(";

            Object[] args = useValue ? getValues() : getKeys();
            if (args != null && args.length > 0) {
                if (quote == null) {
                    quote = "'";
                }

                Object arg;
                for (int i = 0; i < args.length; i++) {
                    arg = args[i];
                    s += (i <= 0 ? "" : ",") + (arg instanceof Boolean || arg instanceof Number ? arg : quote + arg + quote);
                }
            }

            return s + ")";
        }
  1. 拼写错误
    见类 AbstractParser

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions