问题列表 - 第44564页

我应该删除`else if`中不必要的`else`吗?

比较两者:

if (strstr(a, "earth"))     // A1
    return x;
if (strstr(a, "ear"))       // A2
    return y;
Run Code Online (Sandbox Code Playgroud)

if (strstr(a, "earth"))     // B1
    return x;
else if (strstr(a, "ear"))  // B2
    return y;
Run Code Online (Sandbox Code Playgroud)

就个人而言,我觉得这else是多余的,并阻止CPU进行分支预测.

在第一个中,当执行A1时,可以预解码A2.在第二个中,它将不会解释B2,直到B1被评估为假.

我发现使用后一种形式的很多(可能是大多数?)来源.虽然,后一种形式看起来更好理解,因为它不会明显return y只有在a =~ /ear(?!th)/没有else子句的情况下才会调用.

c

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

jquery不会在$ .ajax上为rails标准REST DELETE答案调用成功方法

可能这样的问题不是新的,但我没有发现任何类似的东西.我有这样的jQuery代码:

$.ajax({ 
  url : ('/people/'+id), 
  type : 'DELETE', 
  dataType : 'json', 
  success : function(e) {
    table.getItems(currentPage);
  }
});
Run Code Online (Sandbox Code Playgroud)

我的Rails控制器看起来像这样:

def destroy
    @person = Person.find(params[:id])
    @person.destroy

    respond_to do |format|
      format.html { redirect_to(people_url) }
      format.json  { render :json => @person, :status => :ok }
    end
end
Run Code Online (Sandbox Code Playgroud)

这很有效.

但是当我使用以下内容(由标准生成)时,success不会调用回调:

def destroy
    @person = Person.find(params[:id])
    @person.destroy

    respond_to do |format|
      format.html { redirect_to(people_url) }
      format.json  { head :ok }
    end
end
Run Code Online (Sandbox Code Playgroud)

测试下rails 3.0.3,jQuery 1.4.2Firefox 3.6.13.
Firebug说,在这两种情况下都会触发查询并返回200 OK,在这两种情况下都会删除项目.但在第二种情况下,不会调用回调. …

rest jquery ruby-on-rails

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

php - postgresql最大执行时间

是否可以选择在PHP中使用PostgreSQL函数,因此您可以为查询指定最大执行时间?我不想从配置文件中启用它,因为只需要限制某些查询.

php postgresql

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

捕获SeekBar值

在我的Android应用程序中,我有一个TextView和一个SeekBar.这两个值都用于按钮单击计算结果.

问题是如何捕获SeekBar值并将其转换为String以进行计算.

代码如下:

class clicker implements Button.OnClickListener {
    public void onClick(View v) {
        String a,b;
        Integer vis;
        a = txtbox3.getText().toString();
        b = slider1.getContext().toString();
        vis = (Integer.parseInt(a)*Integer.parseInt(b))/100;
        tv.setText(vis.toString());
    }
}
Run Code Online (Sandbox Code Playgroud)

请帮忙.提前致谢.

android seekbar

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

在编辑器中键入时Visual Studio崩溃

我已经使用VS2010几个星期但是在过去的几天它已经完全无法使用,当我在编辑器中输入任何内容时Visual Studio抛出一个异常,然后我得到了很多intellisence错误(代码很好,我可以编译如果我在尝试使用编辑器之前运行它 - 这是日志消息:

  <entry>
    <record>241</record>
    <time>2011/01/25 08:30:34.109</time>
    <type>Error</type>
    <source>Editor or Editor Extension</source>
    <description>System.InvalidCastException: Unable to cast COM object of type &apos;System.__ComObject&apos; to interface type &apos;Microsoft.VisualStudio.TextManager.Interop.IVsTextReplaceEvents&apos;. This operation failed because the QueryInterface call on the COM component for the interface with IID &apos;{CF9928D9-65AE-4319-A446-94ED5C45ECDE}&apos; failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&#x000D;&#x000A;   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, Boolean&amp; pfNeedsRelease)&#x000D;&#x000A;   at Microsoft.VisualStudio.TextManager.Interop.IVsTextReplaceEvents.OnReplace(ChangeInput[] pCI)&#x000D;&#x000A;   at Microsoft.VisualStudio.Editor.Implementation.VsTextBufferAdapter.OnTextBufferChangedHighPriority(Object sender, TextContentChangedEventArgs e)&#x000D;&#x000A;   at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args)</description> …
Run Code Online (Sandbox Code Playgroud)

crash intellisense editor visual-studio-2010

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

比较整数

$a = somenumber;
$b = somenumber;
Run Code Online (Sandbox Code Playgroud)

我如何知道哪个变量的编号最大?这项任务的简短方法是什么?

每个数字是没有残留的正整数.

谢谢.

php integer compare

-2
推荐指数
1
解决办法
4407
查看次数

Rails 3提交带有链接的表单

如何使用正确的rails 3格式链接提交表单?谢谢.

<%= form_for @post do |f| %>
<%= f.label :title %><br>
<%= f.text_field :title %>
<p><%= f.submit %></p>
<% end %>
Run Code Online (Sandbox Code Playgroud)

我的代码示例.

forms ruby-on-rails hyperlink

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

使用Perl-XML忽略格式错误的XML

我正在使用perl命令行实用程序xpath从一些HTML代码中提取数据,如下所示:

#!/bin/bash
echo $HTML | xpath -q -e "//h2[1]"
Run Code Online (Sandbox Code Playgroud)

HTML格式错误导致xpath抛出以下错误:

not well-formed (invalid token) at line X, column Y, byte Z:
Run Code Online (Sandbox Code Playgroud)

我无法真正修复HTML,因为它是由外部源提供的,这意味着每次更改HTML时我都必须再次手动修复它.

我找了一个很空的xpath man:http: //www.linuxcertif.com/man/1/xpath.1p/

我想知道是否有办法告诉xpath忽略格式错误的HTML.为了让您了解它的错误形式,请参阅源代码中的几行:

<div id="header-background" style="top: 42px; >&nbsp;</div> <---- missing closing "
<div id-"page-inner">   <---- - instead of =
Run Code Online (Sandbox Code Playgroud)

谢谢

html xml perl html-parsing xml-parsing

0
推荐指数
1
解决办法
1528
查看次数

如何使用MongoDB大于/小于?

我正在使用pymongo驱动程序.

有人可以看看pymongo并告诉我如何做更大的事情?我曾经做过:为了一切.

python database mongodb

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

软键盘进来时如何保持某些组件固定?

我的应用程序是一个聊天应用程序,它的 UI 是:

应用程序的标题
列表视图
聊天消息、输入框和发送按钮

但问题是当我单击编辑文本时,软键盘会出现并将所有内容向上推,但我需要标题留在屏幕上。我已经把它贴简化问题的图像和UI代码这里。(我不能在这篇文章中发布多个链接或图片,因为我是 Stack Overflow 的新手。)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView android:text="Header contents" android:layout_width="fill_parent"
        android:textSize="20sp" android:gravity="center_horizontal"
        android:layout_height="wrap_content" />
    <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_weight="1" />

    <EditText android:text="" android:layout_gravity="bottom"
        android:id="@+id/EditText01" android:layout_width="fill_parent"
        android:layout_height="wrap_content"></EditText>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Android 在默认消息应用程序中有此要求。

有没有人有任何想法?

layout android

7
推荐指数
1
解决办法
5348
查看次数