summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgcramer <remarcg@gmx.net>2019-01-15 14:44:42 (GMT)
committergcramer <remarcg@gmx.net>2019-01-15 14:44:42 (GMT)
commit0700557ccb9dfdc6dbb4fc095570e3178d3522c3 (patch)
tree826b7a80497e6fc09804e22a836d8424e5aa1c7a
parent2ab266714dbe135b01018b88d7a140da22621acc (diff)
downloadtk-0700557ccb9dfdc6dbb4fc095570e3178d3522c3.zip
tk-0700557ccb9dfdc6dbb4fc095570e3178d3522c3.tar.gz
tk-0700557ccb9dfdc6dbb4fc095570e3178d3522c3.tar.bz2
(1) Computation of most specialized event (PREFER_MOST_SPECIALIZED_EVENT) changed to make it more user-friendly
(2) Minor modifications in bind.test (only textual changes)
-rw-r--r--generic/tkBind.c24
-rw-r--r--tests/bind.test34
2 files changed, 30 insertions, 28 deletions
diff --git a/generic/tkBind.c b/generic/tkBind.c
index e8ca3e0..4d7970d 100644
--- a/generic/tkBind.c
+++ b/generic/tkBind.c
@@ -754,10 +754,6 @@ void TkpDumpPSList(const PSList *psList);
static int BindCount = 0;
#endif
-#if PREFER_MOST_SPECIALIZED_EVENT
-static unsigned Sqr(unsigned x) { return x*x; }
-#endif
-
static unsigned Max(unsigned a, unsigned b) { return a < b ? b : a; }
static int Abs(int n) { return n < 0 ? -n : n; }
static bool IsOdd(int n) { return n & 1; }
@@ -2121,24 +2117,30 @@ IsBetterMatch(
if (diff > 0) { return true; }
if (diff < 0) { return false; }
- if (sndMatchPtr->count > fstMatchPtr->count) { return true; }
- if (sndMatchPtr->count < fstMatchPtr->count) { return false; }
-
#if PREFER_MOST_SPECIALIZED_EVENT
{ /* local scope */
- unsigned fstCount = 0;
- unsigned sndCount = 0;
+#define M (Tcl_WideUInt)1000000
+ static const Tcl_WideUInt weight[5] = { 0, 1, M, M*M, M*M*M };
+#undef M
+ Tcl_WideUInt fstCount = 0;
+ Tcl_WideUInt sndCount = 0;
unsigned i;
/*
* Count the most high-ordered patterns.
+ *
+ * (This computation assumes that a sequence does not contain more than
+ * 1,000,000 single patterns. It can be precluded that in practice this
+ * assumption will not be violated.)
*/
for (i = 0; i < fstMatchPtr->numPats; ++i) {
- fstCount += Sqr(GetCount(fstMatchPtr, i));
+ assert(GetCount(fstMatchPtr, i) < SIZE_OF_ARRAY(weight));
+ fstCount += weight[GetCount(fstMatchPtr, i)];
}
for (i = 0; i < sndMatchPtr->numPats; ++i) {
- sndCount += Sqr(GetCount(sndMatchPtr, i));
+ assert(GetCount(sndMatchPtr, i) < SIZE_OF_ARRAY(weight));
+ sndCount += weight[GetCount(sndMatchPtr, i)];
}
if (sndCount > fstCount) { return true; }
if (sndCount < fstCount) { return false; }
diff --git a/tests/bind.test b/tests/bind.test
index d6d23bb..b9b47aa 100644
--- a/tests/bind.test
+++ b/tests/bind.test
@@ -6358,7 +6358,7 @@ test bind-33.1 {prefer longest match} -setup {
} -cleanup {
destroy .t.f
} -result {a11}
-test bind-33.2 {should prefer most specialized event} -setup {
+test bind-33.2 {should prefer most specific event} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6373,10 +6373,10 @@ test bind-33.2 {should prefer most specialized event} -setup {
destroy .t.f
# This test case shows that old implementation has an issue, because
# in my opinion it is expected that <Double-1> is matching, this binding
- # is more specialized. But new implementation will be conform to old,
+ # is more specific. But new implementation will be conform to old,
# and so "11" is the expected result.
} -result {11}
-test bind-33.3 {should prefer most specialized event} -setup {
+test bind-33.3 {should prefer most specific event} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6393,10 +6393,10 @@ test bind-33.3 {should prefer most specialized event} -setup {
destroy .t.f
# Also this test case shows that old implementation has an issue, it is
# expected that <a><Double-1><a> is matching, because <Double-1> is more
- # specialized than <1><1>. But new implementation will be conform to old,
+ # specific than <1><1>. But new implementation will be conform to old,
# and so "11" is the expected result.
} -result {11}
-test bind-33.4 {prefer most specialized event} -setup {
+test bind-33.4 {prefer most specific event} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6413,7 +6413,7 @@ test bind-33.4 {prefer most specialized event} -setup {
# here <1><1> will be triggered correctly, but this is not consistent with
# test case 33.2.
} -result {11}
-test bind-33.5 {prefer most specialized} -setup {
+test bind-33.5 {prefer most specific} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6427,7 +6427,7 @@ test bind-33.5 {prefer most specialized} -setup {
} -cleanup {
destroy .t.f
} -result {11}
-test bind-33.6 {prefer most specialized} -setup {
+test bind-33.6 {prefer most specific} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6445,7 +6445,7 @@ test bind-33.6 {prefer most specialized} -setup {
} -cleanup {
destroy .t.f
} -result {1111}
-test bind-33.7 {prefer most specialized} -setup {
+test bind-33.7 {prefer most specific} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6459,7 +6459,7 @@ test bind-33.7 {prefer most specialized} -setup {
} -cleanup {
destroy .t.f
} -result {1}
-test bind-33.8 {prefer most specialized} -setup {
+test bind-33.8 {prefer most specific} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6474,7 +6474,7 @@ test bind-33.8 {prefer most specialized} -setup {
} -cleanup {
destroy .t.f
} -result {1}
-test bind-33.9 {prefer last in case of homogeneous patterns} -setup {
+test bind-33.9 {prefer last in case of homogeneous equal patterns} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6491,7 +6491,7 @@ test bind-33.9 {prefer last in case of homogeneous patterns} -setup {
} -cleanup {
destroy .t.f
} -result {last}
-test bind-33.10 {prefer last in case of homogeneous patterns} -setup {
+test bind-33.10 {prefer last in case of homogeneous equal patterns} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6508,7 +6508,7 @@ test bind-33.10 {prefer last in case of homogeneous patterns} -setup {
} -cleanup {
destroy .t.f
} -result {last}
-test bind-33.11 {should prefer most specialized} -setup {
+test bind-33.11 {should prefer most specific} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6530,10 +6530,10 @@ test bind-33.11 {should prefer most specialized} -setup {
destroy .t.f
# This test case shows that old implementation has an issue, because
# in my opinion it is expected that first one is matching, this binding
- # is more specialized. But new implementation will be conform to old,
+ # is more specific. But new implementation will be conform to old,
# and so "last" is the expected result.
} -result {last}
-test bind-33.12 {prefer last in case of homogeneous patterns} -setup {
+test bind-33.12 {prefer last in case of homogeneous equal patterns} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6547,7 +6547,7 @@ test bind-33.12 {prefer last in case of homogeneous patterns} -setup {
} -cleanup {
destroy .t.f
} -result {last}
-test bind-33.13 {prefer last in case of homogeneous patterns} -setup {
+test bind-33.13 {prefer last in case of homogeneous equal patterns} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6564,7 +6564,7 @@ test bind-33.13 {prefer last in case of homogeneous patterns} -setup {
# because both bindings are homogeneous equal, so the latter must
# be preferred.
} -result {last}
-test bind-33.14 {prefer last in case of homogeneous patterns} -setup {
+test bind-33.14 {prefer last in case of homogeneous equal patterns} -setup {
pack [frame .t.f]
focus -force .t.f
update
@@ -6580,7 +6580,7 @@ test bind-33.14 {prefer last in case of homogeneous patterns} -setup {
} -cleanup {
destroy .t.f
} -result {last}
-test bind-33.15 {prefer last in case of homogeneous patterns} -setup {
+test bind-33.15 {prefer last in case of homogeneous equal patterns} -setup {
pack [frame .t.f]
focus -force .t.f
update