forked from qt-creator/qt-creator
OS X: Create a help AutoreleasePool class
That wraps NSAutoreleasePool and releases it at destruction. Change-Id: Ie7049450da46458f02c02d38439e20e43609ca83 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
51
src/libs/utils/autoreleasepool.h
Normal file
51
src/libs/utils/autoreleasepool.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms and
|
||||
** conditions see http://www.qt.io/terms-conditions. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef AUTORELEASEPOOL_H
|
||||
#define AUTORELEASEPOOL_H
|
||||
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class AutoreleasePool
|
||||
{
|
||||
public:
|
||||
AutoreleasePool() { pool = [[NSAutoreleasePool alloc] init]; }
|
||||
~AutoreleasePool() { [pool release]; }
|
||||
private:
|
||||
NSAutoreleasePool *pool;
|
||||
};
|
||||
|
||||
} // Utils
|
||||
|
||||
#endif // AUTORELEASEPOOL_H
|
||||
|
||||
@@ -28,9 +28,10 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "autoreleasepool.h"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
|
||||
namespace Utils {
|
||||
@@ -38,12 +39,11 @@ namespace Internal {
|
||||
|
||||
QUrl filePathUrl(const QUrl &url)
|
||||
{
|
||||
Utils::AutoreleasePool pool; Q_UNUSED(pool)
|
||||
QUrl ret = url;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSURL *nsurl = url.toNSURL();
|
||||
if ([nsurl isFileReferenceURL])
|
||||
ret = QUrl::fromNSURL([nsurl filePathURL]);
|
||||
[pool release];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,7 @@ FORMS += $$PWD/filewizardpage.ui \
|
||||
RESOURCES += $$PWD/utils.qrc
|
||||
|
||||
osx {
|
||||
HEADERS += $$PWD/autoreleasepool.h
|
||||
OBJECTIVE_SOURCES += \
|
||||
$$PWD/fileutils_mac.mm
|
||||
LIBS += -framework Foundation
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "spotlightlocatorfilter.h"
|
||||
|
||||
#include <utils/autoreleasepool.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QMutex>
|
||||
@@ -82,7 +83,7 @@ SpotlightIterator::SpotlightIterator(const QString &expression)
|
||||
m_queueIndex(-1),
|
||||
m_finished(false)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
Utils::AutoreleasePool pool; Q_UNUSED(pool)
|
||||
NSPredicate *predicate = [NSPredicate predicateWithFormat:expression.toNSString()];
|
||||
m_query = [[NSMetadataQuery alloc] init];
|
||||
m_query.predicate = predicate;
|
||||
@@ -109,7 +110,6 @@ SpotlightIterator::SpotlightIterator(const QString &expression)
|
||||
m_waitForItems.wakeAll();
|
||||
}] retain];
|
||||
[m_query startQuery];
|
||||
[pool release];
|
||||
}
|
||||
|
||||
SpotlightIterator::~SpotlightIterator()
|
||||
@@ -161,7 +161,7 @@ void SpotlightIterator::ensureNext()
|
||||
return;
|
||||
if (m_index >= 10000) // limit the amount of data that is passed on
|
||||
return;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
Utils::AutoreleasePool pool; Q_UNUSED(pool)
|
||||
// check if there are items in the queue, otherwise wait for some
|
||||
m_mutex.lock();
|
||||
bool itemAvailable = (m_queueIndex + 1 < m_queue.count);
|
||||
@@ -177,7 +177,6 @@ void SpotlightIterator::ensureNext()
|
||||
|
||||
}
|
||||
m_mutex.unlock();
|
||||
[pool release];
|
||||
}
|
||||
|
||||
// #pragma mark -- SpotlightLocatorFilter
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "openpagesmanager.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/autoreleasepool.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QApplication>
|
||||
@@ -68,26 +69,7 @@
|
||||
#import <WebKit/WebUIDelegate.h>
|
||||
#import <WebKit/WebView.h>
|
||||
|
||||
// #pragma mark -- AutoreleasePool
|
||||
|
||||
class AutoreleasePool
|
||||
{
|
||||
public:
|
||||
AutoreleasePool();
|
||||
~AutoreleasePool();
|
||||
private:
|
||||
NSAutoreleasePool *pool;
|
||||
};
|
||||
|
||||
AutoreleasePool::AutoreleasePool()
|
||||
{
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
}
|
||||
|
||||
AutoreleasePool::~AutoreleasePool()
|
||||
{
|
||||
[pool release];
|
||||
}
|
||||
using namespace Utils;
|
||||
|
||||
// #pragma mark -- mac helpers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user