perf(execution): reuse component UID within each snapshot read

This commit is contained in:
阿白叔 committed 2026-10-19 10:36:06 +08:00
1 parent 13b9ff48dd
commit 5b625b076e
2 files changed
+75 -13

No files matched your search

+16 -13
View File
@@ -459,8 +459,8 @@ Sub QPEnsureComponentIndex()
End If
End Sub
Function QPComponentPins(ByRef Comp)
Dim Context, LocalIndex, AllPins, CmpPin, Owner, Bucket, Count, ComponentUid
Function QPComponentPins(ByVal ComponentUid)
Dim Context, LocalIndex, AllPins, CmpPin, Owner, Bucket, Count
Context = QPCanonicalPath(QPProjectPath()) & "|" & QPSheetIdentity()
If Not IsObject(QP_PinIndex) Then Set QP_PinIndex = Nothing
If Not QP_PinIndex Is Nothing Then
@@ -490,7 +490,6 @@ Function QPComponentPins(ByRef Comp)
QPLog QP_Root, "INFO", "pin_index_built count=" & Count
QPProgress "index_pins", Count, Count
End If
ComponentUid = CStr(Comp.UID)
If QP_PinIndex.Exists(ComponentUid) Then
Set QPComponentPins = QP_PinIndex.Item(ComponentUid)
Else
@@ -1258,13 +1257,13 @@ Function QPUntouchedFullState(ByRef Comp)
Dim Point, Pins, Connections, Attr, AttributeText, Result, Uid
Uid = CStr(Comp.UID)
Set Point = Comp.GetLocation()
Set Pins = QPComponentPins(Comp)
Set Pins = QPComponentPins(Uid)
If Pins.Count = 0 Then
' A genuinely empty query is valid for annotation symbols; COM errors
' still propagate. Selected replacement symbols continue to require pins.
Connections = "NO_PINS"
Else
Connections = QPConnectionSignatureFromPins(Comp, Pins)
Connections = QPConnectionSignatureFromPins(Uid, Pins)
End If
Result = "C" & vbTab & QPEncode(Uid) & vbTab & QPEncode(CStr(Comp.Refdes)) & _
vbTab & QPEncode(CStr(Point.X)) & vbTab & QPEncode(CStr(Point.Y)) & _
@@ -1363,10 +1362,13 @@ Function QPSnapshotComponent(ByRef Comp)
Dim ErrorNumber
Dim ErrorSource
Dim ErrorDescription
Dim Uid, Pins
Uid = CStr(Comp.UID)
Set Point = Comp.GetLocation()
Connections = QPConnectionSignature(Comp)
Result = "C" & vbTab & QPEncode(CStr(Comp.UID)) & vbTab & _
Set Pins = QPComponentPins(Uid)
Connections = QPConnectionSignatureFromPins(Uid, Pins)
Result = "C" & vbTab & QPEncode(Uid) & vbTab & _
QPEncode(CStr(Comp.Refdes)) & vbTab & QPEncode(CStr(Point.X)) & _
vbTab & QPEncode(CStr(Point.Y)) & vbTab & _
QPEncode(CStr(Comp.Orientation)) & vbTab & QPEncode(CStr(Comp.Scale)) & _
@@ -1377,7 +1379,7 @@ Function QPSnapshotComponent(ByRef Comp)
AttributeText = ""
AttributeCount = 0
For Each Attr In Comp.Attributes
AttributeText = AttributeText & QPSnapshotAttribute(CStr(Comp.UID), Attr)
AttributeText = AttributeText & QPSnapshotAttribute(Uid, Attr)
If Err.Number <> 0 Then Exit For
AttributeCount = AttributeCount + 1
QPProgress "snapshot_attributes", AttributeCount, 0
@@ -2484,12 +2486,13 @@ Function QPEffectiveAttributeValue(ByRef Attr)
End Function
Function QPConnectionSignature(ByRef Comp)
Dim Pins
Set Pins = QPComponentPins(Comp)
QPConnectionSignature = QPConnectionSignatureFromPins(Comp, Pins)
Dim Pins, Uid
Uid = CStr(Comp.UID)
Set Pins = QPComponentPins(Uid)
QPConnectionSignature = QPConnectionSignatureFromPins(Uid, Pins)
End Function
Function QPConnectionSignatureFromPins(ByRef Comp, ByRef Pins)
Function QPConnectionSignatureFromPins(ByVal ComponentUid, ByRef Pins)
Dim PinIndexKey
Dim PinReadCount
Dim CmpPin
@@ -2513,7 +2516,7 @@ Function QPConnectionSignatureFromPins(ByRef Comp, ByRef Pins)
PinReadCount = 0
For Each PinIndexKey In Pins.Keys
Set CmpPin = Pins.Item(CStr(PinIndexKey))
If StrComp(CStr(CmpPin.Component.UID), CStr(Comp.UID), _
If StrComp(CStr(CmpPin.Component.UID), ComponentUid, _
vbBinaryCompare) = 0 Then
Set Point = CmpPin.GetLocation()
PinKey = CStr(CmpPin.Number) & "|" & CStr(Point.X) & "|" & _
+59
View File
@@ -372,6 +372,65 @@ WScript.Echo CStr(CBool(InStr(Text,"net1|GND")>0))
assert output.splitlines() == ['2', 'True']
@pytest.mark.parametrize(('reader', 'pin_count', 'expected_reads'), [
('QPUntouchedFullState', 0, 1),
('QPUntouchedFullState', 2, 5),
('QPSnapshotComponent', 2, 5),
('QPConnectionSignature', 2, 5),
])
def test_component_capture_reads_its_uid_once_and_keeps_live_pin_owner_checks(
tmp_path, reader, pin_count, expected_reads):
fake = FULL_FAKE.replace('Public UID, Refdes, X, Y, Orientation, Scale, Attributes, Selected, RaiseOnFind',
'Private StoredUid\n Public UidReads\n Public Refdes, X, Y, Orientation, Scale, Attributes, Selected, RaiseOnFind')
fake = fake.replace(' Function FindAttribute(ByVal Name)\n', '''
Public Property Let UID(ByVal Value)
StoredUid=Value
End Property
Public Property Get UID
UidReads=UidReads+1
UID=StoredUid
End Property
Function FindAttribute(ByVal Name)
''', 1)
output = run_vbs(tmp_path, UNTOUCHED_ROUTINES + ['QPSnapshotComponent'], '''
Dim Comp, Attr, Pin, Text, Item
Set QP_App=New FakeApp
Set Comp=New FullComponent: Comp.UID="u2": Comp.Refdes="R2"
For Item=1 To 6
Set Attr=New FullAttribute: Attr.Name="Field" & CStr(Item)
Comp.Attributes.Add Attr,True
Next
For Item=1 To ''' + str(pin_count) + '''
Set Pin=New FakePin: Set Pin.Component=Comp
Pin.Number=CStr(Item): Pin.X=Item: Pin.Y=0: Set Pin.Connection=Nothing
QP_App.ActiveView.Pins.Add Pin,True
Next
Comp.UidReads=0
Text=''' + reader + '''(Comp)
WScript.Echo Comp.UidReads
WScript.Echo CStr(Len(Text)>0)
''', LOG_STUB + fake)
assert output.splitlines() == [str(expected_reads), 'True']
def test_pin_owner_is_rechecked_when_reusing_the_index(tmp_path):
output = run_vbs(tmp_path, UNTOUCHED_ROUTINES, '''
Dim Comp, Other, Pin, Text
Set QP_App=New FakeApp
Set Comp=New FullComponent: Comp.UID="u2": Comp.Refdes="R2"
Set Other=New FullComponent: Other.UID="other": Other.Refdes="R3"
Set Pin=New FakePin: Set Pin.Component=Comp
Pin.Number="1": Pin.X=10: Pin.Y=0: Set Pin.Connection=Nothing
QP_App.ActiveView.Pins.Add Pin,True
Text=QPConnectionSignature(Comp)
Set Pin.Component=Other
On Error Resume Next
Text=QPConnectionSignature(Comp)
WScript.Echo CStr(Err.Number=vbObjectError+819)
''', LOG_STUB + FULL_FAKE)
assert output == 'True'
@pytest.mark.parametrize(('mutation', 'expected'), [
('Comp.X = 20', 'True'), ('Comp.Orientation = 90', 'True'),
('Comp.Scale = 2', 'True'), ('Attr.Color = 99', 'True'),