perf(execution): use native-host full snapshots for owned batches

This commit is contained in:
阿白叔 committed 2026-10-19 11:07:13 +08:00
1 parent 2f6060dfe3
commit 81f34683ea
9 files changed
+261 -14

No files matched your search

@@ -46,6 +46,37 @@ Function QPNativeCommandPathSupported(ByVal Path)
QPNativeCommandPathSupported = (Len(Path) > 0)
End Function
Function QPTryNativeVerifyUntouched(ByRef Records)
Dim Selected, Record, Index, Actual
QPTryNativeVerifyUntouched = False
QPRequireRecordsContext Records
Set Selected = CreateObject("Scripting.Dictionary")
For Index = 0 To Records("components").Count - 1
Set Record = Records("components").Item(CStr(Index))
Selected.Add CStr(Record("uid")), True
Next
Set Actual = QPNativeReadUntouched(Selected)
If Actual Is Nothing Then Exit Function
QPRequireRecordsContext Records
QPCompareNativeUntouched Records, Actual
QPTryNativeVerifyUntouched = True
End Function
Sub QPCompareNativeUntouched(ByRef Records, ByRef Actual)
Dim Baseline, FullBaseline, Rows, Uid, Expected
Set Baseline = Records("untouched")
Set FullBaseline = Records("untouched_full")
Set Rows = Actual("rows")
If Actual("total") <> Baseline.Count + Records("components").Count Or Rows.Count <> Baseline.Count Then _
QPNativeReadInvalid "component count changed outside selected targets"
For Each Uid In Baseline.Keys
If Not Rows.Exists(Uid) Or Not FullBaseline.Exists(Uid) Then QPNativeReadInvalid "unselected component missing"
Expected = CStr(Baseline(Uid)) & vbCrLf & "G" & vbTab & QPEncode(Uid) & vbTab & _
QPEncode(CStr(FullBaseline(Uid))) & vbCrLf
If Rows(Uid) <> Expected Then QPNativeReadInvalid "unselected component changed"
Next
End Sub
Function QPParseNativeSnapshot(ByVal Text, ByVal Token, ByVal Project, ByVal Sheet, ByRef SelectedUids)
Dim Lines, Fields, Last, Index, Uid, Identity, State, Pair, Rows, Result, Total
Set Rows = CreateObject("Scripting.Dictionary")
+39 -9
View File
@@ -1114,7 +1114,7 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
Dim PartNumber
Dim Snapshot
Dim Index
Dim Selectors, Selector, Uid, ValueAttr, ValueText, MatchedUids, UntouchedCount
Dim Selectors, Selector, Uid, ValueAttr, ValueText, MatchedUids, UntouchedCount, NativeRead
If StrComp(CStr(Command("old_part_number")), CStr(Command("new_part_number")), vbTextCompare) = 0 Then _
Err.Raise vbObjectError + 829, "QuickPartReplace", "source and target must differ"
@@ -1188,15 +1188,26 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
Set Comp = Matches.Item(CStr(Index))
MatchedUids.Add CStr(Comp.UID), True
Next
Set NativeRead = Nothing
If QPUseNativeSnapshot() Then
QPRequireProject Command
Set NativeRead = QPNativeReadUntouched(MatchedUids)
End If
UntouchedCount = 0
For Each Comp In Components
If Not MatchedUids.Exists(CStr(Comp.UID)) Then
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
Snapshot = Snapshot & QPUntouchedComponent(Comp)
UntouchedCount = UntouchedCount + 1
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
End If
Next
If NativeRead Is Nothing Then
For Each Comp In Components
If Not MatchedUids.Exists(CStr(Comp.UID)) Then
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
Snapshot = Snapshot & QPUntouchedComponent(Comp)
UntouchedCount = UntouchedCount + 1
QPProgress "capture_untouched", UntouchedCount, Components.Count - Matches.Count
End If
Next
Else
If NativeRead("total") <> Components.Count Then _
Err.Raise vbObjectError + 875, "QuickPartReplace.NativeRead", "component count changed during capture"
Snapshot = Snapshot & CStr(NativeRead("text"))
End If
QPWriteUtf8 SnapshotPath, Snapshot
For Each Comp In Components
@@ -1212,6 +1223,22 @@ Sub QPCaptureAndSelect(ByRef Command, ByVal SnapshotPath)
QPLog QP_Root, "INFO", "awaiting_native_replace count=" & Matches.Count
End Sub
Function QPUseNativeSnapshot()
Dim Reader, Number
QPUseNativeSnapshot = False
If Not QP_BatchMode Or Not QP_OwnedProject Then Exit Function
If Len(CStr(CreateObject("WScript.Shell").Environment("PROCESS")("DXPART_DESKTOP"))) = 0 Then Exit Function
On Error Resume Next
Set Reader = GetRef("QPNativeReadUntouched")
Number = Err.Number
Err.Clear
On Error GoTo 0
If Number <> 0 Then Exit Function
If QPCanonicalPath(QP_OwnedProjectPath) <> QPProjectPath() Then _
Err.Raise vbObjectError + 875, "QuickPartReplace.NativeRead", "native reader does not own the active project"
QPUseNativeSnapshot = True
End Function
Function QPUntouchedComponent(ByRef Comp)
Dim State, Identity, Fields
State = QPUntouchedFullState(Comp)
@@ -1294,6 +1321,9 @@ Sub QPVerifyUntouched(ByRef Records)
' Read new component/pin proxies after each native mutation, restore or reopen.
QPInvalidatePinIndex
QPInvalidateComponentIndex
If QPUseNativeSnapshot() Then
If QPTryNativeVerifyUntouched(Records) Then Exit Sub
End If
Set Components = QP_App.ActiveView.Query(VDM_COMP, VD_ALL)
Matched = 0
Total = 0