データベースを使おうと思ったり理由は、実機テストで信じられないくらい時間がかかったため。
Win32 では数秒の処理が数十分かかった。
これはどうも、動的配列を逐次大きくして追加していた部分にあったみたい
procedure TWordList.AddItem(aWordRecord: TWordRecord);
begin
SetLength(Self.Items, Length(Self.Items) + 1);
Self.Items[High(Items)].Assign(aWordRecord);
end;
procedure TWordList.Load(aPathFileName: string);
var
i: Integer;
tmpWordRecord: TWordRecord;
tmpRecordList: TStringList;
tmpFieldList: TStringList;
tmpString: String;
begin
// DeleteFile(aPathFileName);
self.Clear;
if FileExists(aPathFileName) then
begin
tmpFieldList := TStringList.Create;
tmpRecordList := TStringList.Create;
tmpRecordList.LoadFromFile(aPathFileName);
for i := 0 to tmpRecordList.Count - 1 do
begin
tmpFieldList.Delimiter := chr(DEMILITR_CHR);
tmpFieldList.StrictDelimiter := False;
tmpString := tmpRecordList[i];
tmpFieldList.DelimitedText := tmpString;
tmpWordRecord.Word := trim(tmpFieldList[0]);
tmpWordRecord.Japanese := trim(tmpFieldList[1]);
tmpWordRecord.Japanese := StringReplace(tmpWordRecord.Japanese, chr(ESCAPE_COMMA_CHR), ',', [rfReplaceAll]);
tmpWordRecord.Japanese := StringReplace(tmpWordRecord.Japanese, chr(ESCAPE_SPACE_CHR), ' ', [rfReplaceAll]);
self.AddItem(tmpWordRecord);
end;
tmpRecordList.Free;
tmpFieldList.Free;
end;
end;
最初に配列の大きさを決定して、代入するととてつもなく早くなった。
これで、データベースを使う必要はなくなった。
procedure TWordList.Load(aPathFileName: string);
var
i: Integer;
tmpWordRecord: TWordRecord;
tmpRecordList: TStringList;
tmpFieldList: TStringList;
tmpString: String;
begin
self.Clear;
if FileExists(aPathFileName) then
begin
tmpFieldList := TStringList.Create;
tmpRecordList := TStringList.Create;
tmpRecordList.LoadFromFile(aPathFileName);
SetLength(Self.Items, tmpRecordList.Count);
for i := 0 to tmpRecordList.Count - 1 do
begin
tmpFieldList.Delimiter := chr(DEMILITR_CHR);
tmpFieldList.StrictDelimiter := False;
tmpString := tmpRecordList[i];
tmpFieldList.DelimitedText := tmpString;
tmpWordRecord.Word := trim(tmpFieldList[0]);
tmpWordRecord.Japanese := trim(tmpFieldList[1]);
tmpWordRecord.Japanese := StringReplace(tmpWordRecord.Japanese, chr(ESCAPE_COMMA_CHR), ',', [rfReplaceAll]);
tmpWordRecord.Japanese := StringReplace(tmpWordRecord.Japanese, chr(ESCAPE_SPACE_CHR), ' ', [rfReplaceAll]);
Self.Items[i].Assign(tmpWordRecord);
// self.AddItem(tmpWordRecord);
end;
tmpRecordList.Free;
tmpFieldList.Free;
end;
end;