Entwickler-Ecke

Algorithmen, Optimierung und Assembler - Function optimization


mohfa - Do 25.02.10 15:53
Titel: Function optimization
Hi all, I want to optimize this function ; is there any other better alternative :


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
function StringToken(const line: Pointer; Fieldno: Integer; const delim: Char; var Fields, Linepos: Integer): String;
var
    counter, cn: integer;
    cur: char;
    i, ln: integer;
begin
    result  := '';
    counter := fields;
    cn      := 0;
    ln      := length(string(line^));

    for i := linepos to ln do begin
        cur := string(line^)[i];
        if cur = delim then begin
            asm inc counter end;
            if counter > fieldno then begin
                Result := copy(string(line^), linepos, cn);

                linepos := i;
                fields  := counter - 1;
                exit;
            end else begin
                linepos := i + 1;
                Continue;
            end;
        end;
        if fieldno = counter then
            inc(cn);
        
    end;
    Result := copy(string(line^), linepos, cn);
    linepos := i + 1;
    fields  := counter - 1;

end;


many thanks


BenBE - Fr 26.02.10 20:18

Use the version from the Fast Code project you included in your project anyways.


mohfa - Fr 26.02.10 21:44

Thank you BenBE .... :)