我做了一个测试来比较几种语言的字符串操作,以便为服务器端应用程序选择一种语言.结果似乎很正常,直到我最终尝试了C++,这让我感到非常惊讶.所以我想知道我是否错过了任何优化并来到这里寻求帮助.
测试主要是密集的字符串操作,包括连接和搜索.测试在Ubuntu 11.10 amd64上进行,GCC版本为4.6.1.该机器是戴尔Optiplex 960,配备4G内存和四核CPU.
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)
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) 我在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) 我想在列表视图中显示用户个人资料图片.当我尝试从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)?
我有一个看起来如下的标签:
<Label Name="FalsePositiveInput" Content="✓">
Run Code Online (Sandbox Code Playgroud)
这有效,但我怎么能在代码隐藏中做到这一点?我试过这个,但显然它不起作用:
FalsePositiveInput.Content = "✓";
Run Code Online (Sandbox Code Playgroud)
我想要显示的字符是复选标记符号
是否有可能将鼠标事件传递NSWindow给它后面的任何东西(即使它是来自另一个应用程序的窗口)?
我正在使用NSWindow创建桌面覆盖,但仍希望能够与其他窗口进行交互,即使它们位于我的覆盖窗口后面.
我真的想在Xcode中创建一个简单的文件浏览器,就像Finder本身一样,但它只是将一个文件夹显示为网格视图.任何人都可以指导我指导吗?
我尝试学习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) 你如何使应用程序只支持景观?在xcode 3中,没有肖像模式只是整个事物的风景吗?
我正在制作一个OS X应用程序,我需要获取Mac模型,例如:
iMac11,3
MacBook3,1
Run Code Online (Sandbox Code Playgroud)
等等.是否有任何课程或功能得到它?
我目前正在使用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>
任何帮助将非常感激.
cocoa ×4
ios ×3
objective-c ×3
c++ ×2
macos ×2
.net ×1
android ×1
c# ×1
facebook ×1
file-browser ×1
iphone ×1
mouseevent ×1
node.js ×1
nswindow ×1
performance ×1
python ×1
regex ×1
stl ×1
unicode ×1
wpf ×1