jeudi 2 février 2017

Any way to optimise this loop?

So I am writing a program which reads logs from different files, sorts them by a given status and outputs them to the accordingly files. There are approx. 8-10k logs at any time and I currently have this wile loop to check their status :

    private void SortByStatus(TreeSet<Log> allLogs) {
    Iterator<Log> iter = allLogs.iterator();
    while(iter.hasNext()){
        Log temp = iter.next();
        if(temp.getLogStatus() == Log.Status.INFO)
            INFOlogs.add(temp);
        if(temp.getLogStatus() == Log.Status.WARN)
            WARNlogs.add(temp);
        if(temp.getLogStatus() == Log.Status.DEBUG)
            DEBUGlogs.add(temp);
        if(temp.getLogStatus() == Log.Status.ERROR)
            ERRORlogs.add(temp);
    }
}

I was just wondering if this can be improved in any way, even marginally faster would be nice if possible

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire