Дайте совет по оптимизации, написал 2 варианта кода, какой лучше:
| Код | function Tdatamodule_Connection.FindById2(ItemId, Where: Integer): Integer; var OldItemID: Integer; B: Boolean; begin Result := -1; if ConnectionStatus = csConnected then begin SelectionStatus := ssByKey; try OldItemID := Ffield_item_id.AsInteger; B := False; case Where of
W_ITEMS: B := cmp_TableByKey_.FindKey([ItemId]) and (Ffield_group_id.AsInteger <> 0) and (Ffield_flags.AsLargeInt <> 1);
W_SECTIONS: B := cmp_TableByKey_.FindKey([ItemId]) and (Ffield_group_id.AsInteger = 0) and (Ffield_flags.AsLargeInt <> 1);
W_ITEMS_AND_SECTIONS: B := cmp_TableByKey_.FindKey([ItemId]) and (Ffield_flags.AsLargeInt <> 1);
else raise Exception.CreateResFmt(@const_msg_InvalidWhereParam, [Where]); end; Result := Integer(B); WhereStatus := Where; if Result = 0 then cmp_TableByKey_.FindKey([OldItemID]); except on E: Exception do LastMsgError := E.Message; end; end else LastMsgError := LoadResString(@const_msg_ConnectionNotExists); end;
|
или
| Код | function Tdatamodule_Connection.FindById2(ItemId, Where: Integer): Integer; var OldItemID: Integer; B: Boolean; begin Result := -1; if ConnectionStatus = csConnected then try SelectionStatus := ssByKey; OldItemID := Ffield_item_id.AsInteger; B := cmp_TableByKey_.FindKey([ItemId]) and (Ffield_flags.AsLargeInt <> 1); case Where of
W_ITEMS: B := B and (Ffield_group_id.AsInteger <> 0);
W_SECTIONS: B := B and (Ffield_group_id.AsInteger = 0);
W_ITEMS_AND_SECTIONS:;
else raise Exception.CreateResFmt(@const_msg_InvalidWhereParam, [Where]); end; Result := Integer(B); WhereStatus := Where; if Result = 0 then cmp_TableByKey_.FindKey([OldItemID]); except on E: Exception do LastMsgError := E.Message; end else LastMsgError := LoadResString(@const_msg_ConnectionNotExists); end;
|
|