removed LinkedLists in BaseDisplay and Image. Only 1 left in BaseDisplay now

This commit is contained in:
Dana Jansens 2002-05-12 21:46:02 +00:00
parent ebdf25bf67
commit eb8a11a5a7
4 changed files with 45 additions and 43 deletions

View file

@ -91,6 +91,8 @@
#include "LinkedList.h" #include "LinkedList.h"
#include "Timer.h" #include "Timer.h"
#include <algorithm>
// X error handler to handle any and all X errors while the application is // X error handler to handle any and all X errors while the application is
// running // running
static Bool internal_error = False; static Bool internal_error = False;
@ -338,11 +340,9 @@ BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) {
timerList = new LinkedList<BTimer>; timerList = new LinkedList<BTimer>;
screenInfoList = new LinkedList<ScreenInfo>; screenInfoList.reserve(ScreenCount(display));
for (int i = 0; i < number_of_screens; i++) { for (int i = 0; i < number_of_screens; i++)
ScreenInfo *screeninfo = new ScreenInfo(*this, i); screenInfoList.push_back(new ScreenInfo(*this, i));
screenInfoList->insert(screeninfo);
}
#ifndef NOCLOBBER #ifndef NOCLOBBER
NumLockMask = ScrollLockMask = 0; NumLockMask = ScrollLockMask = 0;
@ -390,14 +390,8 @@ BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) {
BaseDisplay::~BaseDisplay(void) { BaseDisplay::~BaseDisplay(void) {
while (screenInfoList->count()) { std::for_each(screenInfoList.begin(), screenInfoList.end(),
ScreenInfo *si = screenInfoList->first(); PointerAssassin());
screenInfoList->remove(si);
delete si;
}
delete screenInfoList;
// we don't create the BTimers, we don't delete them // we don't create the BTimers, we don't delete them
while (timerList->count()) while (timerList->count())

View file

@ -33,6 +33,8 @@ class ScreenInfo;
#include "LinkedList.h" #include "LinkedList.h"
#include "Timer.h" #include "Timer.h"
#include "Geometry.h" #include "Geometry.h"
#include "Util.h"
#include <vector>
#define AttribShaded (1l << 0) #define AttribShaded (1l << 0)
#define AttribMaxHoriz (1l << 1) #define AttribMaxHoriz (1l << 1)
@ -127,7 +129,10 @@ private:
Bool _startup, _shutdown; Bool _startup, _shutdown;
Display *display; Display *display;
LinkedList<ScreenInfo> *screenInfoList;
typedef std::vector<ScreenInfo*> ScreenInfoList;
ScreenInfoList screenInfoList;
LinkedList<BTimer> *timerList; LinkedList<BTimer> *timerList;
char *display_name, *application_name; char *display_name, *application_name;
@ -270,8 +275,10 @@ public:
#endif // NEWWMSPEC #endif // NEWWMSPEC
inline ScreenInfo *getScreenInfo(int s) inline ScreenInfo *getScreenInfo(int s) {
{ return (ScreenInfo *) screenInfoList->find(s); } ASSERT(s < screenInfoList.size());
return screenInfoList[s];
}
inline const Bool &hasShapeExtensions(void) const inline const Bool &hasShapeExtensions(void) const
{ return shape.extensions; } { return shape.extensions; }

View file

@ -2057,8 +2057,6 @@ BImageControl::BImageControl(BaseDisplay &dpy, ScreenInfo &scrn, Bool _dither,
getVisual()->c_class); getVisual()->c_class);
exit(1); exit(1);
} }
cache = new LinkedList<Cache>;
} }
@ -2087,16 +2085,16 @@ BImageControl::~BImageControl(void) {
delete [] colors; delete [] colors;
} }
if (cache->count()) { if (!cache.empty()) {
int i, n = cache->count(); int i, n = cache.size();
fprintf(stderr, i18n->getMessage(ImageSet, ImagePixmapRelease, fprintf(stderr, i18n->getMessage(ImageSet, ImagePixmapRelease,
"BImageContol::~BImageControl: pixmap cache - " "BImageContol::~BImageControl: pixmap cache - "
"releasing %d pixmaps\n"), n); "releasing %d pixmaps\n"), n);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
Cache *tmp = cache->first(); Cache *tmp = cache.front();
XFreePixmap(basedisplay.getXDisplay(), tmp->pixmap); XFreePixmap(basedisplay.getXDisplay(), tmp->pixmap);
cache->remove(tmp); cache.remove(tmp);
delete tmp; delete tmp;
} }
@ -2107,18 +2105,17 @@ BImageControl::~BImageControl(void) {
} }
#endif // TIMEDCACHE #endif // TIMEDCACHE
} }
delete cache;
} }
Pixmap BImageControl::searchCache(unsigned int width, unsigned int height, Pixmap BImageControl::searchCache(unsigned int width, unsigned int height,
unsigned long texture, unsigned long texture,
BColor *c1, BColor *c2) { BColor *c1, BColor *c2) {
if (cache->count()) { if (!cache.empty()) {
LinkedListIterator<Cache> it(cache);
for (Cache *tmp = it.current(); tmp; it++, tmp = it.current()) { CacheList::iterator it;
for (it = cache.begin(); it != cache.end(); ++it) {
Cache *tmp = *it;
if ((tmp->width == width) && (tmp->height == height) && if ((tmp->width == width) && (tmp->height == height) &&
(tmp->texture == texture) && (tmp->pixel1 == c1->getPixel())) (tmp->texture == texture) && (tmp->pixel1 == c1->getPixel()))
if (texture & BImage_Gradient) { if (texture & BImage_Gradient) {
@ -2163,9 +2160,9 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height,
else else
tmp->pixel2 = 0l; tmp->pixel2 = 0l;
cache->insert(tmp); cache.push_back(tmp);
if ((unsigned) cache->count() > cache_max) { if ((unsigned) cache.size() > cache_max) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, i18n->getMessage(ImageSet, ImagePixmapCacheLarge, fprintf(stderr, i18n->getMessage(ImageSet, ImagePixmapCacheLarge,
"BImageControl::renderImage: cache is large, " "BImageControl::renderImage: cache is large, "
@ -2184,8 +2181,9 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height,
void BImageControl::removeImage(Pixmap pixmap) { void BImageControl::removeImage(Pixmap pixmap) {
if (pixmap) { if (pixmap) {
LinkedListIterator<Cache> it(cache); CacheList::iterator it;
for (Cache *tmp = it.current(); tmp; it++, tmp = it.current()) { for (it = cache.begin(); it != cache.end(); ++it) {
Cache *tmp = *it;
if (tmp->pixmap == pixmap) { if (tmp->pixmap == pixmap) {
if (tmp->count) { if (tmp->count) {
tmp->count--; tmp->count--;
@ -2434,11 +2432,13 @@ void BImageControl::parseColor(BColor *color, const char *c) {
void BImageControl::timeout(void) { void BImageControl::timeout(void) {
LinkedListIterator<Cache> it(cache); CacheList::iterator it;
for (Cache *tmp = it.current(); tmp; it++, tmp = it.current()) { for (it = cache.begin(); it != cache.end(); ) {
Cache *tmp = *it;
++it; // move on to the next item before this one is removed
if (tmp->count <= 0) { if (tmp->count <= 0) {
XFreePixmap(basedisplay.getXDisplay(), tmp->pixmap); XFreePixmap(basedisplay.getXDisplay(), tmp->pixmap);
cache->remove(tmp); cache.remove(tmp);
delete tmp; delete tmp;
} }
} }

View file

@ -26,8 +26,8 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "LinkedList.h"
#include "Timer.h" #include "Timer.h"
#include <list>
class ScreenInfo; class ScreenInfo;
class BImage; class BImage;
@ -186,7 +186,8 @@ private:
unsigned long pixel1, pixel2, texture; unsigned long pixel1, pixel2, texture;
} Cache; } Cache;
LinkedList<Cache> *cache; typedef std::list<Cache*> CacheList;
CacheList cache;
protected: protected: