summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-26 06:53:29 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-29 02:20:26 (GMT)
commitb3d5b616ed04dfe48f1c67c49243eab636816735 (patch)
treefc96298ccee69b05babd50a92d63335492eb817d
parent27d32e1ccedf1400e6cf5a2d34e542450ffa0eaa (diff)
Fix accounting of bad cache uses.
1. When invoking a copy constructor, we transfer the responsibility of using the cached sin/cos to the new CachingDms object 2. If we are adding / subtracting two CachingDms objects, we have used their sin/cos. 3. Account for CachingDms objects that get destructed before their cos/sin values are used.
-rw-r--r--kstars/auxiliary/cachingdms.cpp33
-rw-r--r--kstars/auxiliary/cachingdms.h15
2 files changed, 44 insertions, 4 deletions
diff --git a/kstars/auxiliary/cachingdms.cpp b/kstars/auxiliary/cachingdms.cpp
index ed07257..fbbd4f9 100644
--- a/kstars/auxiliary/cachingdms.cpp
+++ b/kstars/auxiliary/cachingdms.cpp
@@ -43,6 +43,12 @@ CachingDms::CachingDms( const double &x ) : dms( x )
#endif
}
+#ifdef COUNT_DMS_SINCOS_CALLS
+CachingDms::~CachingDms() {
+ if ( !m_cacheUsed )
+ ++cachingdms_bad_uses;
+}
+#endif
CachingDms::CachingDms(const QString& s, bool isDeg) : dms( s, isDeg ) {
dms::SinCos( m_sin, m_cos );
@@ -139,11 +145,30 @@ CachingDms::CachingDms(const dms& angle) {
#endif
}
+#ifdef COUNT_DMS_SINCOS_CALLS
+CachingDms::CachingDms( const CachingDms &o ) {
+ m_sin = o.sin();
+ m_cos = o.cos();
+ D = o.D;
+ m_cacheUsed = false;
+}
+CachingDms& CachingDms::operator =( const CachingDms &o ) {
+ if ( !m_cacheUsed )
+ ++cachingdms_bad_uses;
+ m_sin = o.sin();
+ m_cos = o.cos();
+ D = o.D;
+ m_cacheUsed = false;
+ return ( *this );
+}
+#endif
+
+
// Makes trig identities more readable:
-#define sinA a.m_sin
-#define cosA a.m_cos
-#define sinB b.m_sin
-#define cosB b.m_cos
+#define sinA a.sin()
+#define cosA a.cos()
+#define sinB b.sin()
+#define cosB b.cos()
// We use trigonometric addition / subtraction formulae to speed up
// computation. This way, we have no trigonometric function calls at
diff --git a/kstars/auxiliary/cachingdms.h b/kstars/auxiliary/cachingdms.h
index 3ad4f9e..5aacf4d 100644
--- a/kstars/auxiliary/cachingdms.h
+++ b/kstars/auxiliary/cachingdms.h
@@ -59,6 +59,13 @@ public:
*/
explicit CachingDms( const int &d, const int &m=0, const int &s=0, const int &ms=0 );
+#ifdef COUNT_DMS_SINCOS_CALLS
+ /**
+ * @short Destructor must count bad cache uses
+ */
+ ~CachingDms();
+#endif
+
/**
* @short Sets the angle in degrees supplied as a double
* @note Re-implements dms::setD() with sine/cosine caching
@@ -196,6 +203,14 @@ public:
*/
CachingDms( const dms &angle );
+#ifdef COUNT_DMS_SINCOS_CALLS
+ /**
+ * Copy constructor that sets m_cacheUsed to true
+ */
+ CachingDms( const CachingDms &o );
+ CachingDms& operator =( const CachingDms &o );
+#endif
+
private:
double m_sin, m_cos; // Cached values