小编一二三*_*一二三的帖子

为什么std :: string操作表现不佳?

我做了一个测试来比较几种语言的字符串操作,以便为服务器端应用程序选择一种语言.结果似乎很正常,直到我最终尝试了C++,这让我感到非常惊讶.所以我想知道我是否错过了任何优化并来到这里寻求帮助.

测试主要是密集的字符串操作,包括连接和搜索.测试在Ubuntu 11.10 amd64上进行,GCC版本为4.6.1.该机器是戴尔Optiplex 960,配备4G内存和四核CPU.

在Python(2.7.2)中:

def test():
    x = ""
    limit = 102 * 1024
    while len(x) < limit:
        x += "X"
        if x.find("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0) > 0:
            print("Oh my god, this is impossible!")
    print("x's length is : %d" % len(x))

test()
Run Code Online (Sandbox Code Playgroud)

结果如下:

x's length is : 104448

real    0m8.799s
user    0m8.769s
sys     0m0.008s
Run Code Online (Sandbox Code Playgroud)

在Java中(OpenJDK-7):

public class test {
    public static void main(String[] args) {
        int x = 0;
        int limit = 102 * 1024;
        String s="";
        for (; s.length() …
Run Code Online (Sandbox Code Playgroud)

c++ python performance stl node.js

59
推荐指数
6
解决办法
2万
查看次数

NS_ENUM和NS_OPTIONS有什么区别?

我在Xcode5中使用clang预处理了以下代码.

typedef NS_ENUM(NSInteger, MyStyle) {
    MyStyleDefault,
    MyStyleCustom
};

typedef NS_OPTIONS(NSInteger, MyOption) {
    MyOption1 = 1 << 0,
    MyOption2 = 1 << 1,
};
Run Code Online (Sandbox Code Playgroud)

得到了这个.

typedef enum MyStyle : NSInteger MyStyle; enum MyStyle : NSInteger {
    MyStyleDefault,
    MyStyleCustom
};

typedef enum MyOption : NSInteger MyOption; enum MyOption : NSInteger {
    MyOption1 = 1 << 0,
    MyOption2 = 1 << 1,
};
Run Code Online (Sandbox Code Playgroud)

我知道NS_OPTIONS用于位掩码,但是有任何技术差异吗?或者这仅仅是为了命名约定?

编辑

根据NS_OPTIONS的定义,它可能与编译器兼容.(特别是对于c ++编译器)

// In CFAvailability.h
// Enums and Options
#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c ios

30
推荐指数
3
解决办法
2万
查看次数

从Facebook Graph-API获取用户图片

我想在列表视图中显示用户个人资料图片.当我尝试从android调用graph-api来检索图像时,我总是得到以下错误.

java.io.IOException: Hostname <fbcdn-profile-a.akamaihd.net> was not verified
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:170)
    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:398)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.sendRequest(HttpURLConnection.java:1224)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1558)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1551)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1052)
    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.getInputStream(HttpsURLConnection.java:252)
    at com.facebook.android.Util.openUrl(Util.java:200)
    at com.facebook.android.Facebook.request(Facebook.java:559)
Run Code Online (Sandbox Code Playgroud)

这是我使用的代码:

private static void retrieveProfilePicture(String userId) throws MalformedURLException, IOException{
        facebook = FacebookHelper.getInstance();
        Bundle bundle = new Bundle();
        bundle.putString(Facebook.TOKEN, facebook.getAccessToken());
        Object picture = facebook.request("/"+userId+"/picture", bundle, "GET");
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中执行相同的调用(https://graph.facebook.com//picture?access_token=)时,我会在这样的URL上返回图像 https://fbcdn-profile-a.akamaihd.net/...

以什么格式传送给我的图像?带有引用映像的JSON(url)?

android facebook facebook-graph-api

20
推荐指数
3
解决办法
5万
查看次数

如何在代码隐藏中将Unicode字符设置为Label的内容?

我有一个看起来如下的标签:

<Label Name="FalsePositiveInput" Content="&#x2713;">
Run Code Online (Sandbox Code Playgroud)

这有效,但我怎么能在代码隐藏中做到这一点?我试过这个,但显然它不起作用:

FalsePositiveInput.Content = "&#x2713;";
Run Code Online (Sandbox Code Playgroud)

我想要显示的字符是复选标记符号

.net c# unicode wpf

18
推荐指数
2
解决办法
2万
查看次数

NSWindow:通过窗口将鼠标事件传递给下面的任何东西

是否有可能将鼠标事件传递NSWindow给它后面的任何东西(即使它是来自另一个应用程序的窗口)?

我正在使用NSWindow创建桌面覆盖,但仍希望能够与其他窗口进行交互,即使它们位于我的覆盖窗口后面.

macos cocoa mouseevent nswindow

16
推荐指数
1
解决办法
2343
查看次数

在Cocoa中创建一个文件浏览器

我真的想在Xcode中创建一个简单的文件浏览器,就像Finder本身一样,但它只是将一个文件夹显示为网格视图.任何人都可以指导我指导吗?

cocoa file-browser

15
推荐指数
1
解决办法
7306
查看次数

第854页的"The C++ Programming Language Third Edition"中的代码是否正确?

我尝试学习C++.在"The C++ Programming Language Third Edition"一书中,我找到了第854页的代码(附录C.13.1):

template<class T> class X {
    static T def_val;
    static T* new_X(T a = def_val);
};

template<class T> T X<T>::def_val(0, 0);
template<class T> T* X<T>::new_X(T a) { /* ... */ }

template<> int X<int>::def_val<int> = 0;
template<> int* X<int>::new_X<int>(int i) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)

我修改它:

template<class T> class X {
    static T def_val;
    static T* new_X(T a = def_val);
};

template<class T> T X<T>::def_val(0, 0);
template<class T> T* X<T>::new_X(T a) { return new T(a); …
Run Code Online (Sandbox Code Playgroud)

c++

13
推荐指数
2
解决办法
796
查看次数

你如何使应用程序只支持景观?

你如何使应用程序只支持景观?在xcode 3中,没有肖像模式只是整个事物的风景吗?

screen-orientation ios

13
推荐指数
4
解决办法
1万
查看次数

在Cocoa中获取Mac型号

我正在制作一个OS X应用程序,我需要获取Mac模型,例如:

iMac11,3
MacBook3,1
Run Code Online (Sandbox Code Playgroud)

等等.是否有任何课程或功能得到它?

macos cocoa objective-c

10
推荐指数
1
解决办法
5587
查看次数

NSRegularExpression:用<a>标签替换url文本

我目前正在使用UIWebView来设计来自twitter的帖子.一些推文当然包含URL,但不包含<a>标签.我能够提取URL,但是我不知道如何添加<a>标签并将其放回到推文中.然后,我将使用相同的方法添加@usernames和#hashtags的链接.以下是我当前代码的示例:

NSString *tweet = @"Sync your files to your Google Docs with a folder on your desktop.  Like Dropbox.  Good choice, Google storage is cheap. http://ow.ly/4OaOo";

NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))" options:NSRegularExpressionCaseInsensitive error:NULL];

NSString *match = [tweet substringWithRange:[expression rangeOfFirstMatchInString:tweet options:NSMatchingCompleted range:NSMakeRange(0, [tweet length])]];
NSLog(@"%@", match);// == http://ow.ly/4OaOo
Run Code Online (Sandbox Code Playgroud)

最终,我希望最终的字符串看起来像这样:

Sync your files to your Google Docs with a folder on your desktop. Like Dropbox. Good choice, Google storage is cheap. <a href="http://ow.ly/4OaOo>http://ow.ly/4OaOo</a>

任何帮助将非常感激.

regex iphone objective-c ios

9
推荐指数
1
解决办法
6142
查看次数