clone

Does cloning provide a performance improvement over constructors/factory methods?

南楼画角 提交于 2019-12-22 05:05:14
问题 I'm maintaing an older Java code base (jvm 1.4) that seems to use cloning as an alternative to object instantiation, I'm guessing as a performance optimization. Here's a contrived example: public class Foo { private SomeObject obj; // SomeObject implements Cloneable public Foo() { obj = new SomeObject(); obj.setField1("abc"); // these fields will have the same value every time obj.setField2("def"); } public void doStuff() { SomeObject newObj = obj.clone(); // clone it instead of using a

Both dup and clone return different objects, but modifying them alters the original object

六月ゝ 毕业季﹏ 提交于 2019-12-22 04:46:11
问题 I have an array of values that I use as a reference for order when I'm printing out hash values. I'd like to modify the array so that the array values are "prettier". I figured I'd just dup or clone the array, change the values and the original object would remain unchanaged. However (in irb)... @arr = ['stuff', 'things'] a = @arr.clone b = @arr.dup So, at the very least, a and @arr are different objects: a.object_id == @arr.object_id => false But now it gets strange a[0].capitalize! a => [

How do I “fork” a Stream in .NET?

你说的曾经没有我的故事 提交于 2019-12-22 04:33:35
问题 As discussed before, when a BinaryReader or BinaryWriter gets closed, its underlying Stream get closed as well (aargh). Consider this situation: a routine R is passed a MemoryStream, say M ; I would like to write some stuff to M and then pass it to another routine for more processing (not necessarily writing). For convenience, I'd like to wrap M in a BinaryWriter to do my writing. After writing, I'm done with the BinaryWriter but not with M . void R(MemoryStream M) { using (B = new

Differences between angular.copy() and JSON.parse(JSON.stringify())?

旧巷老猫 提交于 2019-12-22 04:33:26
问题 Can someone explain the differences between angular.copy() and JSON.parse(JSON.stringify())? Are there any? What you will recommend to use? Is angular.fromJson(angular.toJson()) the same as JSON.parse(JSON.stringify())? Just to mention, I've read How do I correctly clone a JavaScript object? for JSON.parse(JSON.stringify()) and angular.copy() reference for angular.copy(). 回答1: What JSON.parse(JSON.stringify()) won't copy: functions any object that has a special representation, like Date (it

git - how can I clone local svn repository?

元气小坏坏 提交于 2019-12-21 06:51:06
问题 I am completely unable to find any explanation how I should specify location of existing svn repository. In other words - what should be used as URL in git svn clone URL when svn repository is local? 回答1: You should be able to succeed like this: git svn clone file:///e/svn_repo_on_E_drive Similar to svn checkout command: svn co file:///e/svn_repo_on_E_drive file:// for folder on the current drive of the executing CMD prompt, file:///d/some_folder for D:\some_folder . Note: The extra / and the

Deep clone without some fields

喜欢而已 提交于 2019-12-21 04:15:33
问题 Let's I have next javascript object. Now I want clone it but without some fields. For example I want cloned object without field "lastName" and "cars.age" Input { "firstName":"Fred", "lastName":"McDonald", "cars":[ { "type":"mersedes", "age":5 }, { "model":"bmw", "age":10 } ] } Output (cloned) { "firstName":"Fred", "cars":[ { "model":"mersedes" }, { "model":"bmw" } ] } I can do something like var human = myJson var clone = $.extend(true, {}, human) delete clone.lastName _.each(clone.cars,

Is it possible to clone an IEnumerable<T> instance, saving a copy of the iteration state?

梦想与她 提交于 2019-12-21 03:56:08
问题 I'd like to create a copy of an IEnumerator<T> so that I can restart the enumeration process from a particular location in the collection. Clearly, there is no benefit to doing so for collections that implement IList , since we can remember the index of interest. Is there a clever way to accomplish this task using a combination of yield statements and Linq functions? I could not find a suitable Clone() method to copy the enumerator, and would like to avoid using Enumerable.Skip() to

Change inner elements id during clone

梦想的初衷 提交于 2019-12-21 03:53:40
问题 I'm doing a clone of a DIV element on button click, I'm able to change the value of ID of the DIV element I'm cloning. But is it possible to change the id of the inner element. In the below code I'm changing the Id of #selection while cloning, I need to dynamically change the id #select . <div id="selections"> <div class="input-group" id="selection"> <span class="input-group-addon"> <i class="icon wb-menu" aria-hidden="true"></i> </span> <select class="show-tick" data-plugin="select2" id=

object cloning with out implementing cloneable interface

六月ゝ 毕业季﹏ 提交于 2019-12-21 03:35:22
问题 to clone the object do i need to implement 'cloneable' interface. because here my class is a jar file(i mean API). so i can't edit the class. i heard that all classes are extends the base object class and this object class implements cloneable interface. does that mean can we directly clone the object with out implementing the interface. if so in my eclipse i am not getting any option to clone the object. is there any other way to clone the object without implementing the cloneable interface

can't clone git repos via http; info/refs not found

北城余情 提交于 2019-12-20 10:06:04
问题 I am trying to make a git repository available for read-only access over http. I am doing it the old-style way because git-http-backend is not available on my host system. That is, I am simply putting the bare repository in a http accessible location. I created the bare repository successfully on the host using git clone --bare <some-remote-location> . Now, when I point git to the new clone using git clone http://my.host.name/location , a message reports repository not found . When I capture